Jump to content

Load DLL with LUA Loadlib command

Recommended Posts

hi everyone,


I have just tried to implement an DLL into lua with the loadlib command.


they say it should work but it does not



path = "c:\\windows\\system32\\user32.dll"
   local GetSystemMetrics = assert(loadlib(path, "GetSystemMetrics"))



"Script Error:

Attempt to call global 'loadlib' (a nil value)


Is there a way of enabling this?


It would increase the possibilities of Leadwerks and Lua a Lot and it would allow us to make better leadwerks projects so that leadwerks can get more famous and bought more often!!

Share this post

Link to post

Tools->Options->uncheck Sandbox Lua. Note this means your game won't work in the LE Game Launcher app then.

Share this post

Link to post

I already did this .. The two lines of code really work for you?

Maybe you can test one for me a bit wacko.png

for me it shows the errormessage...

Share this post

Link to post

You simply can not use a regular dll for lua. It must be built for lua http://lua-users.org/wiki/CreatingBinaryExtensionModules and http://lua-users.org/wiki/CreatingBinaryExtensionModules . If you really want to use a dll, there are probably ways to do it, but all of them are non trivial. I recommend luajit because leadwerks supports that. http://luajit.org/ext_ffi_tutorial.html


Quick and dirty:


local ffi = require( 'ffi' )

ffi.cdef [[

int GetSystemMetrics(int test);


local user32 = ffi.load(ffi.os == "Windows" and "user32" )

error("Screen Dimensions " .. tostring(user32.GetSystemMetrics(0)) .. "x" .. tostring(user32.GetSystemMetrics(1)))


You will be searching through header files.

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...