lua-users home
lua-l archive

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

In Lua 5.2 'require' no longer puts the value returned by the module into the global namespace, so you should do something like:

	cb = require("cb") -- on the lua interpreter command line

	local cb = require("cb") -- in source code

If you depend on the old behavior you have to set the value of the global variable 'cb' yourself, using something like

	lua_pushvalue(L, -1);
	lua_setglobal(L, "cb");

(right after luaL_newlib)

In my own code I just use

	local mymod = require 'mymod'

This has better performance because 'mymod' is a local variable.


On Mon, 19 Sep 2011, wrote:

I have a single-function module build with Visual Studio 2010 that
apparently loads but its function cannot be accessed because the entries
in package.loaded are nil.  Below print(type(cb)) returns nil while all
other k's in package.loaded return table.

Obviously, I am doing something wrong?

Here is a link to the code for the module:

C:\Documents and Settings\e0058060\My
Lua 5.2.0 (beta)  Copyright (C) 1994-2011, PUC-Rio
for k,v in pairs(package.loaded) do print(k,v) end
string  table: 003588E8
debug   table: 00358378
package table: 003569F8
_G      table: 00354E80
io      table: 00357868
os      table: 00357528
table   table: 00357578
math    table: 00359780
cb      table: 0035C9A8
coroutine       table: 003571F8
bit32   table: 003591E0
for k,v in pairs(package.loaded.cb) do print(k,v) end
write   function: 00381390

	Allan Pfalzgraf

	4201 North 27 Street
	Milwaukee, WI 53216
	tel: 414 449-6872
	fax: 414 449-6616 <>  <>