Thursday, 5 September 2013

Why can't I read a nested lua table as argument from C function?

Why can't I read a nested lua table as argument from C function?

I'm going to implement a function with C language and which will be called
by Lua script.
This function should receive a lua table(which even contains an array) as
the argument, so I should read the fields in the table.I try to do like
below, but my function is crashing when I run it. Can anyone help my find
the problem?
/*
function findImage(options)
imagePath = options.imagePath
fuzzy = options.fuzzy
ignoreColors = options.ignoreColor;
end
Call Example:
findImage {imagePath="/var/image.png", fuzzy=0.5,
ignoreColors={0xffffff, 0x0000ff, 0x2b2b2b}}
*/
static int findImgProxy(lua_State *L)
{
lua_settop(L, 1);
luaL_checktype(L, 1, LUA_TTABLE);
lua_getfield(L, -1, "imagePath");
lua_getfield(L, -2, "fuzzy");
lua_getfield(L, -3, "ignoreColors");
const char *imagePath = luaL_checkstring(L, -3);
double fuzzy = luaL_checknumber(L, -2);
luaL_checktype(L, -1, LUA_TTABLE);
int count = // how to get the member count of ignoreColor array
int colors[count];
for (int i=0; i

No comments:

Post a Comment