lua-users home
lua-l archive

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

// in your c file
static const luaL_Reg mylib[] = {
 /* add any global functions here */

LUAELALIB_API int luaopen_mylib(lua_State *L) {
 luaL_register(L, "mylibname", mylib);
 /* The mylibname table is now on the stack; add any manipulation of that
table here. */
 return 1;
Build this file to produce your shared lib named "" (It seems to have require("mylib") work, the name of the generated shared lib  must be the same as the name in luaopen_xxx)
Then in lua script file, write :
LUA_PATH="?.so(dll)" -- Don't need to change the source code of lua core lib
require("mylib")  -- use the function registered with mylibname
Hope this can do help to you

2006/4/13, Stockdale, Daire, SOE <>:

Can anyone provide a minimalist tutorial on correct use of the "require"
and "module" functions of 5.1 please, especially with reference to
creating a native Lua module? Or direct me to one?

Lots of thanks,



The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged.  Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else.

If you have received this email in error, please notify us immediately by e-mail on and then delete the email and any copies.  The SEGA Group have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.


Best Regards.

Chen guo
Tongji University, China
Mobile: 13817166264