lua-users home
lua-l archive

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


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of Michael Gerbracht
> Sent: vrijdag 3 januari 2014 13:42
> To: lua-l@lists.lua.org
> Subject: Problems loading .dlls on windows
> 
> I am using Lua for windows and wrote a script that makes use of the lpeg
> library. Up to now I just used require("lpeg") to load the lpeg.dll which is
> part of the Lua for Windows package.
> 
> Now I would like to use the script from within a .net application using NLua
> (x64 version). I get the error message that "lpeg.dll is not a valid Win32
> application". NLua is using lua 5.2 in contrast to LuaForWindows which still
> seems to use lua 5.1. I can imagine that this might be a problem.
> 
> Can you suggest what I have to do to get it working? I have seen that you
> can download lpeg sources - do I have to compile them? Is it possible to use
> Visual Studio for that? Or is there a place I can download another version
> of .dll? I have no experience with compiling C programs...
> 
> thanks,
> Michael
> 

I'm not very knowledgeable about loading dll's dynamically from applications and what stuff is required to make that work but there are at least 2 important things to keep in mind;
1) the modules loaded should be compiled for the same architecture (x64 in your case)
2) they must be compiled against the same 'runtime'

The second might not make sense to you so here it goes; All Microsoft C/C++ compilers compile the source code against a specific runtime. The runtimes used are usually called MSVCRT.dll, MSVCR10.dll (at least for 32bit). The ones with numbers in their name correspond to a specific version of the Microsoft compilers, where the MSVCRT.dll is the 'system runtime' used for device drivers etc. The Lua community seems to standardize on MSVCRT.dll, but NLua is not stock-lua, so you don't know...
The problem with those runtimes is; you can't mix them. Say NLua was built with MSVCR10.dll, then using an lpeg.dll build against MSVCRT.dll will get you in trouble. Generally mixing them will work, until it doesn't in some very unpredictable and hard to troubleshoot way. So you better stay clear of that.

So what to do?
1) Download an application called "DependencyWalker" (google it) using that you can find out what runtime NLua was built against.
2) For compiling I would use LuaRocks, it will do the heavy lifting for you. But you will need to configure it for the correct runtime and architecture. LuaRocks depends on a compiler you must have installed, for MSVCRT dependencies I would use MinGW, for the other ones probably best to stick with the Microsoft compilers (either a Visual Studio Express version, or in the Windows SDK)

Hth
Thijs