[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C API - how to combine lua_createtable and lua_settable
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 2 Mar 2011 20:07:08 -0300
> 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);
Yes. Here's is a snippet from one of my libraries:
LUALIB_API int luaopen_mathx(lua_State *L)
{
luaL_register(L,LUA_MATHLIBNAME,R);
lua_pushnumber(L,INFINITY);
lua_setfield(L,-2,"infinity");
lua_pushnumber(L,NAN);
lua_setfield(L,-2,"nan");
return 1;
}