Any good metatables tutorial?

I’m trying to find a good tutorial about the use of custom metatables but I don’t really get it. Any of you guys can suggest a good tutorial for that?

(I want to make “Classes”)

snip snap cool whip

Metatables and Metamethods

If you want to write an implementation of classes, check out lclass by Andrew McWatters or this one by Klei Entertainment.

I’ve got something pretty much working. Now I’m wondering about effective networking and sync with clients.

At the moment I’m keeping track of every single instance of my class in a global table server side and I send the ‘Index’ and the ‘Template’ to the client and then create a new instance on the client using the index and the template.

My problem lies here, each Instance can have unique values associated with them, what would be the best way to sync the items?

After instancing the class clientside, I effectively create the same instance but using the basic values from the template. Should I also make a function to sync custom values through net.WriteTable()?

Here’s what I’m currently using for changing values:

if SERVER then
util.AddNetworkString( “Cerb.ItemMeta.SyncFieldToOwner” )
function Cerb.ItemMeta:SyncFieldToOwner( tbl )

local ply = self:GetOwner();

if ( IsValidPlayer( ply ) ) and ( tbl ) then	
	tbl._Index = self:GetIndex();
	net.Start( "Cerb.ItemMeta.SyncFieldToOwner" )
		net.WriteTable( tbl )
	net.Send( ply )


if CLIENT then
net.Receive( “Cerb.ItemMeta.SyncFieldToOwner”, function( len )

local tbl = net.ReadTable( len )
if ( not tbl ) or ( not tbl._Index ) then return end

local item = Cerb.Items:GetByIndex( tbl._Index )
tbl._Index = nil;

if ( item ) then
	for key,value in pairs( tbl ) do
		item[key] = value