[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [Experiment] Module system based on static hashing
- From: Stefan <ste@...>
- Date: Thu, 9 Apr 2020 19:13:21 +0200
> Very nice!
Thanks!
> Your solution seems to require some manual editing of luaopen_*
> functions. Your lx_open function in each module contains some of the
> code from the luaopen function plus sometimes inside information, such
> as replicating some of what luaL_newmetatable does (as in
> complex/module.c). I wonder whether this can be avoided with some help
> from the module writer.
This is only because the calling protocol of the lx_open function
deviates from the one luaopen_* uses, i.e. luaopen_* calls the loader
and the loader constructs the module table (using luaL_newlib or
luaL_newmetatable) and returns it. lx_set_lookup_metatable
creates the module table beforehand and passes it to the loader.
But there is no compelling reason for this and it is a good idea
to change it to avoid confusion.
> Perhaps we need an extension of luaL_Reg to
> contain data types. Any thoughts?
This would probably simplify code like this in luaopen_math:
lua_pushnumber(L, PI);
lua_setfield(L, -2, "pi");
lua_pushnumber(L, (lua_Number)HUGE_VAL);
lua_setfield(L, -2, "huge");
lua_pushinteger(L, LUA_MAXINTEGER);
lua_setfield(L, -2, "maxinteger");
lua_pushinteger(L, LUA_MININTEGER);
lua_setfield(L, -2, "mininteger");
I moved those into the static table, too.