[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Why did luaL_openlib/luaL_register go?
- From: Rob Hoelz <rob@...>
- Date: Wed, 8 May 2013 08:16:34 +0200
On Tue, 7 May 2013 17:41:27 -0700 (PDT)
Are Leistad <firstname.lastname@example.org> wrote:
> I'm just tried compiling some ols Lua libraries. I understand that
> luaL_openlib has been deprecated for a while, and that luaL_newlib is
> now the preferred quick method for registering libraries. I've got my
> old libraries to compile using LUA_COMPAT_MODULE, so I'm good.
> However, I haven't found out why luaL_openlib and luaL_register is
> out of the API now. These functions let us register a set of library
> functions with a prefix in a simple way, conveniently giving the
> "mylibprefix.myfunc" syntax. I've spent some time searching and
> browsing, trying to find out why they were deprecated and how to
> achieve the same result now, but nothing obvious has popped up yet.
> Thus I have some questions:
> - why is are these functions now gone?
> - is there a simple way to register a library with the
> "mylibprefix.myfunc" syntax, i.e. something equivalent of
> - are there any reasons to avoid LUA_COMPAT_MODULE?
> I've may very well have missed the obvious here...
> View this message in context:
> Sent from the Lua-l mailing list archive at Nabble.com.
luaL_register is gone because it encouraged developers to place their
libraries in the global namespace, which tends to be a bad idea.
module() was removed for the same reasons. The convention that Lua
library developers are moving towards is to return the library table
from the routine, so you may assign it to a variable in the calling
environment. For example:
/* in C land */
int luaopen_mylib(lua_State *L)
/* load it up with stuff */
-- in Lua land
local mylib = require 'mylib'
Description: PGP signature