lua-users home
lua-l archive

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


Just a thought, perhaps just for Keith Wiles and perhaps for a future standard distribution. It might be useful to have luaL_openlibs accept a luaL_Reg as an additional argument, instead of having it rely on the global static array in linit.c, as it is now. Or perhaps the best of both, having it use the global one in linit.c by default if the additional argument is NULL. It might look something like this in linit.c:

LUALIB_API void luaL_openlibs (lua_State *L, luaL_Reg* customlualibs) { /* Only these two */ const luaL_Reg *lib = customlualibs? customlualibs: lualibs; /* lines were changed. */
	for (; lib->func; lib++) {
		lua_pushcfunction(L, lib->func);
		lua_pushstring(L, lib->name);
		lua_call(L, 1, 0);
	}
}


This way, the application developer can choose to just pass NULL for the default behaviour and be done with it, or first do a call with NULL and then one for his own additional libraries, or only one (or several) call(s) for a completely customized selection of libraries.

Greets,
Mark


From: Rici Lake <lua@ricilake.net>
Reply-To: Lua list <lua@bazar2.conectiva.com.br>
To: Lua list <lua@bazar2.conectiva.com.br>
Subject: Re: How to add users libraries
Date: Thu, 1 Dec 2005 16:44:30 -0500


On 1-Dec-05, at 1:24 PM, Keith Wiles wrote:

I guess what I am asking for is for Lua to provide these hooks in the standard package and any other areas within Lua a developer may want to effect change (to a given point of course). I guess I could be making a big thing over nothing, but it does seem reasonable to me as it would be fairly simple to polish these areas for a cleaner package.

Well, I guess in that case, Luiz's answer was pretty good. linit.c *is* the hook, and it's a pretty good one. All you have to do is create one with the appropriate list in the definition of lualibs; something which could easily be done with a script if you were that way inclined. Since you might not want all of the standard libraries in a given embedded build -- particularly such things as io, os, debug, and loadlib --, customization is likely to be more than just adding to the list, anyway.