lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi!

I'm looking for a good (fast!) way of sharing the C structs of my 
game with the Lua code.
For example, in C I have the struct:

struct MonsterInfo{
 char name[MAX_NAME];
 int health;
};

and in Lua I could have 2  functions:

------------------------------------
function NewMonster(name, health)

 local tbl = {}

 tbl.name = name;

 tbl.health = health;

 function tbl:Die()
  ...
 end

 return tbl 

end

function Damage(ent, amount)

  ent.health = ent.healt - amount

  if ent.health <= 0 then
    ent:Die()
  end

end

------------------------------------

The problem is how to (fast and easy) keep in the same data (struct) 
in Lua and in C.