[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Best way to share "structs" between C and Lua
- From: "jose_marin2 <jose_marin2@...>" <jose_marin2@...>
- Date: Thu, 16 Jan 2003 13:15:39 -0000
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.