lua-users home
lua-l archive

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


> Does this play well with lua_createtable? Could I just do this?
> 
>   const struct luaL_Reg myLib[] = { . . . }l
>   lua_createtable(L,0,(sizeof(myLib)/sizeof(const struct luaL_Reg))-1);
>   luaL_register(L,0,myLib);
> 
>   lua_pushstring(L,"version");
>   lua_pushstring(L,"0.1");
>   lua_settable(L,-3);
>   [...]

If you are going to use lua_createtable, it would be slightly better to
include space for the extra string:

-   lua_createtable(L,0,(sizeof(myLib)/sizeof(const struct luaL_Reg))-1);
+   lua_createtable(L,0,(sizeof(myLib)/sizeof(const struct luaL_Reg)));

(As an unrelated note, it seems simpler to write 'sizeof(myLib[0])'
instead of 'sizeof(const struct luaL_Reg)'.)

-- Roberto