lua-users home
lua-l archive

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


On 2021/10/25 15:28, Sean Conner wrote:
> It was thus said that the Great nerditation once stated:
> 
>   Starting from here:
> 
>> typedef struct {
>> 	char const *name;
>> 	lua_CFunction loaderfn;
>> } Preloader;
>>
>> /* list the Lua modules you want to preload here */
>> static const Preloader preloaders[] = {
>> 	{ "iuplua", &iuplua_open },
>> 	{ NULL, NULL },
>> };
> 
> to here, can be replaced with:
> 
> 	static luaL_Reg const preloaders[] =
> 	{
> 	  { "iuplua" , &iuplua_open },
>           { NULL     , NULL         }
> 	};
> 
>   And from here:
> 
>> 	Preloader const *mod = &preloaders[0];
>> 	while (mod->name != NULL) {
>> 		lua_pushcfunction(L, mod->loaderfn);
>> 		lua_setfield(L, -2, mod->name);
>> 		++mod;
>> 	}
> 
> to here, replace with:
> 
> 	luaL_setfuncs(L,preloaders,0);
> 
> 
>   Just FYI.
> 

ah, thanks a lot.

that's how you know you use too much "high-level" "modern" C++ binding library that you forget the basic APIs.