lua-users home
lua-l archive

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


On Wed, 10 Jun 2020 09:38:22 +0100, Andrew Gierth
<andrew@tao11.riddles.org.uk> wrote:

> >>>>> "Milan" == Milan Obuch <lua-l@dino.sk> writes:  
> 
>  >> > test-lua.c:135:2: warning: implicit declaration of function
>  >> > 'luaL_openlib' is invalid in C99
>  >> > [-Wimplicit-function-declaration]    
>  >> 
>  >> Compile your program with -DLUA_COMPAT_MODULE  
> 
>  Milan> Thank you, this works. In lauxlib.h I see this is for
>  Milan> compatibility with old module system, is there some
>  Milan> replacement in new Lua world without module?  
> 
> See luaL_newlib or luaL_setfuncs. It is not expected any more for
> modules to either manipulate their environment or add themselves into
> any global table; it's the responsibility of require() to add the
> module to package.loaded, the module's luaopen_* function should just
> return a value on the stack.
> 

Currently I am creating metatable with some method like this:

luaL_newmetatable(L,TABLE_ID);
luaL_openlib(L,NULL,table_instance_methods,0);
lua_pop(L,1);

I can then associate this metatable with some variable (I use light
userdata) and this could be used for simple OOP-like programming.

I just could not achive the same effect with luaL_newlibtable and
luaL_setfuncs... I can live with older compatibility solution for now,
but if this example could be seen elsewhere done in new way, I'd like
to test it.

I am still learning Lua, but it is interesting and it looks to me like
quite well designed and engineered language.

Regards,
Milan