lua-users home
lua-l archive

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


>>>>> "Sean" == Sean Conner <sean@conman.org> writes:

 Sean> That's really only an issue with lua 5.1, which *will always*
 Sean> create a global when loading a module.

 >> That does not appear to be the case:
 >> 
 >> > require 'mod'
 >> mod loaded
 >> > print(mod)
 >> nil
 >> > (require 'mod').foo()
 >> foo called

 Sean> Which version of Lua did you use?

I think I actually tried luajit, but it's the same in stock 5.1.

("mod" in my example was a trivial lua module, not C.)

 >> require "lpeg"

lpeg 1.0.1 on lua 5.1 does this:

#define luaL_newlib(L,f) luaL_register(L,"lpeg",f)

(and then it has luaL_newlib(L,...) in the luaopen_lpeg function)

luaL_register is what sets the value of global "lpeg", not the require
itself. If you don't use luaL_register, or use it only with a null name
parameter, then no global is set.

-- 
Andrew.