lua-users home
lua-l archive

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




So basically how do I declare a tablme/struct in lua based on a C
type so I can pass it to C funtions ?


PS: I use tolua to externalize the API and lua 3.2

if you are using tolua, you can bind the struct definition to Lua.
for instance, you can pass tolua the following .pkg code:

struct magic_power
{
 char *name;
 ...
};

if you want to create such an object from Lua, you should also
bind a creator function:

magic_power* create (void);

and then, in Lua, you can write:

local obj = create()
obj.name = "a new name"
...

or you can have a Lua constructor:

function MagicPower (t)
 local obj = create()
 obj.name = t.name
 ...
 return obj
}

and then you can use this constructor:

local obj = MagicPower{ name = "object name", ... }

in both cases, "obj" can be passed as parameter to any other
function, mapped via tolua, that expects a magic_powrer object.

hope this helps.

-- waldemar