lua-users home
lua-l archive

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


2008/11/25 pan shizhu <pan.shizhu@gmail.com>:
> This is documented here: http://www.lua.org/pil/8.2.html

The online PiL is outdated with respect to binary modules.

> On Tue, Nov 25, 2008 at 1:20 PM, Raúl Huertas <rax2003_7@hotmail.com> wrote:
>> I'm starting with lua and i'm very excited learning the C API. Now I know
>> how to load my functions and use them in a lua program, but...
>>
>> I0ve just installed wxWidget and it creates a .so called wx.so. SO when in
>> lua, the standalone interpreter, finds 'require("wx")' laods that library
>> automatically. How this can be done? is there any special function to create
>> in that shared library? a lua_openlib(). How the module get loaded
>> automatically?

The different module searchers that are used by the 'require' function
are described in the online manual [1]

Basically all you need is to define the name of your module along with
its package name, for example foo.bar where foo is the package and bar
is the module name. You then have to create a shared library which
exports a symbol named luaopen_foo_bar (if foo contains additionnal
dots, replace them with underscores). This symbol must be a
lua_CFunction [2]. The shared library should be named with a name
corresponding with one of the entries of package.cpath, for example
foo/bar.so.


[1] http://www.lua.org/manual/5.1/manual.html#pdf-package.loaders
[2] http://www.lua.org/manual/5.1/manual.html#lua_CFunction