[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: http://lua-users.org/wiki/ObjectProperties - one question
- From: Milan Obuch <lua-l@...>
- Date: Wed, 10 Jun 2020 14:18:07 +0200
On Wed, 10 Jun 2020 09:38:22 +0100, Andrew Gierth
> >>>>> "Milan" == Milan Obuch <email@example.com> 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:
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.