lua-users home
lua-l archive

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


But when you say about the use of loadlib() function,
does the file.dll need to be prepared to load 'add-on'
lua functions?

Yes, it must have an initialization function into it that receives a lua_State* and returns an integer. When you use loadlib like this:

-- Lua code
func, error = loadlib("my_library.dll", "my_library_init")

You're actually telling Lua to search for a function called "my_library_init" into "my_library.dll". loadlib() returns it so you can call it from Lua (if something fails nil plus an error string is returned):

if func then
  func()
else
  print("error loading library: " .. error)
end


For more information on how to make modules read http://lua-users.org/wiki/BinaryModuleTutorial (in this example Lua 4.0 is used, but in version 5 it's nearly the same thing).

So, do I need to compile luacom like
a file.dll, just to use it?

You could compile a module into a static library and directly link it against the Lua interpreter (like the standard Lua library, for example) so it's always available without needing the DLL. But loading DLLs is more flexible and there's no need to modify the source of the Lua interpreter. As you might guess LuaCheia (and other similar Lua distributions like LuaX) use DLLs so they're modular.

-ap

Attachment: PGP.sig
Description: Mensaje firmado digitalmente