lua-users home
lua-l archive

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


On Fri, Mar 4, 2011 at 21:43, luciano de souza <luchyanus@gmail.com> wrote:
> If I understood, "require" calls a function passing the name of the
> module. The return of this function is placed in package.loaded.

Yes. Something like that.

Suppose you compiled your library as "myawesomelib.dll" and your
package.cpath is "?.dll" and your open function is
"luaopen_myawesomelib", then:

package.cpath = '?.dll'
require 'myawesomelib'


If your luaopen_myawesomelib() "returns" a table (i.e.: it leaves a
table at the top of the stack), then you can assign it to a local:

local mylib = require 'myawesomelib'

Also, package.loaded[ "myawesomelib" ] will contain the same table
aforementioned. In fact, it will hold anything your loader function
returns. You could return a string, a number, a function etc. If you
return "nil" or don't return anything at all, then it will be set to
"true" (boolean).

--rb