lua-users home
lua-l archive

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


Thanks both of you for these valuable inputs :)



>> |  luaL_newmetatable(L, "SelSurface"); |
>> |  lua_pushstring(L, "__index"); |
>> |  lua_pushvalue(L, -2); |
>> |  lua_settable(L, -3); /* metatable.__index = metatable */ |
>> |  luaL_register(L, NULL, SelSurfaceM); |
>> |  luaL_register(L,"SelSurface", SelSurfaceLib); |
>> }
>>
>> to newer Lua :(
>
>        void include_SelSurface(lua_State *L)
>        {
>          luaL_newmetatable(L,"SelSurface");
>          lua_pushvalue(L,-1);
>          lua_setfield(L,-2,"__index");
>          luaL_setfuncs(L,SelSurfaceM,0);
>          luaL_newlib(L,SelSurfaceLib);
>          lua_setglobal(L,"SelSurface");
>        }

If I'm not making a mistake, this syntaxe is working starting Lua 5.2 and is not reconize by Lua 5.1 ? (it's make my code compatible with as large as possible Lua version).

> And if you're making a separate module to be used with require(), name
> it luaopen_<module name>, compile it as a shared library, and avoid
> creating a global:
>
> void luaopen_SelSurface(lua_State *L)
> {
>  luaL_newmetatable(L,"SelSurface");
>  lua_pushvalue(L,-1);
>  lua_setfield(L,-2,"__index");
>  luaL_setfuncs(L,SelSurfaceM,0);
>  luaL_newlib(L,SelSurfaceLib);
>
>  return 1
> }
>
> and then in Lua,
>
> local SelSurface = require("SelSurface")

In fact, the concept is to have Lua embedded in Séléné (like it is in Conky) which makes easier (for me :) ) internal dependencies management and it's consistent with my other project (Marcel) where Lua is "only" an enduser helper.
Anyway, I keep this in mind for other project more Lua centric.

Nice W.E.

Laurent