Jump to content

Load DLL with LUA Loadlib command


MaxAigner
 Share

Recommended Posts

hi everyone,

 

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

http://www.lua.org/pil/8.2.html#C-packages

they say it should work but it does not

 

Main.lua


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

 

Error:

"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!!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

 Share

×
×
  • Create New...