Rick Posted February 23, 2015 Share Posted February 23, 2015 You don't have to include the lib files too. It's an either or thing. Either all source, or header + lib. The lib file is a compiled version of the cpp files. http://lua-users.org/wiki/LoadLibrary Quote Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 23, 2015 Author Share Posted February 23, 2015 I tried loading my DLL with this: local dll = assert(package.loadlib("C:\root\to\simpleDLL.dll", "luaopen_power")) which results in: "The specified procedure could not be found." Also, I don't have a lua.exe file on my computer. :/ Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Rick Posted February 23, 2015 Share Posted February 23, 2015 You don't need lua.exe on your computer. The LE executables is basically the "Lua.exe" as it runs the lua code. Show me your C++ DLL code. I'm not sure if that's referring to package.loadlib() or it can't find luaopen_power. Are you running in sandbox mode? Be sure you aren't. Look at this example code. Also, I noticed in your code you were using static classes. IF you still have issues remove all that and just go straight C to just make sure you can get easy examples like this working. Then you can play around with organizing things differently. It's just best to make a working simple example of this process first. http://lua-users.org/wiki/CreatingBinaryExtensionModules Quote Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 23, 2015 Author Share Posted February 23, 2015 I'm thinking it might be to do with the other DLL files I linked into my VS project, info. I'm not running in sandbox mode, and I think it can't find "luaopen_power". simpleDLL.h extern "C" { #include "lua.h" #include "lauxlib.h" #include "lualib.h" } static int isquare(lua_State *L); static int icube(lua_State *L); int luaopen_power(lua_State *L); simpleDLL.cpp #include "simpleDLL.h" static int isquare(lua_State *L) { float rtrn = (float)(lua_tonumber(L, -1)); printf("Top of square(), nbr = %f\n", rtrn); lua_pushnumber(L, rtrn * rtrn); return 1; } static int icube(lua_State *L) { float rtrn = (float)(lua_tonumber(L, -1)); printf("Top of cube(), number=%f\n", rtrn); lua_pushnumber(L, rtrn*rtrn*rtrn); return 1; } int luaopen_power(lua_State *L) { lua_register(L, "square", isquare); lua_register(L, "cube", icube); return 0; } Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Rick Posted February 23, 2015 Share Posted February 23, 2015 You need to define your luaopen_power with int __declspec(dllexport) Otherwise the function isn't visible by things outside the DLL itself. I generally make a define like #define DLL_EXPORT __declspec(dllexport) int DLL_EXPORT luaopen_power(lua_State *L) { lua_register(L, "square", isquare); lua_register(L, "cube", icube); return 0; } Also I'm not sure if your functions inside need to be static. Play around with that. Quote Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 23, 2015 Author Share Posted February 23, 2015 Okay. I've defined it, now I get: "The specified module could not be found." lol I think we're getting somewhere though. I've read that this message can be given if my DLL is dependent on other DLL files. The only things dependent would be the Lib files I included in the VS project. Could this be the issue here? Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Rick Posted February 23, 2015 Share Posted February 23, 2015 Remove that lib file and try it. If you have the source code of Lua in the project you don't need the lib file anyway, and if it's not statically built then it would be relying on another DLL which could be the issue. Or try putting some lua.dll in the same directory as your DLL, although not needing it would be more ideal. Quote Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 23, 2015 Author Share Posted February 23, 2015 I've now created a fresh and simplified VS project: just the "luaopen_power()" exists which prints a message when called. We're now back to: "The specified procedure could not be found.", and I've attempted loading the DLL with both require() and package.loadlib(). I may try again tomorrow. lol EDIT: I may even just buy the Standard Edition of LE, especially seeing as it's on sale now. Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Rick Posted February 23, 2015 Share Posted February 23, 2015 If I have time tonight I'll put together a little example. Doing this is still beneficial and it can help add many other 3rd party functionality to the Lua version. Quote Link to comment Share on other sites More sharing options...
shadmar Posted February 23, 2015 Share Posted February 23, 2015 Like for RakNetLua : http://estudiodeaplicaciones.com/raknetlua/ ? DLL download : https://mega.co.nz/#!VMBASCia!IUa6MJOYefBpOhgEnA0AOJKiwiTpJ5vVCcdv7YrnlrA Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Rick Posted February 23, 2015 Share Posted February 23, 2015 Oh nice someone finally did that. I exposed a bare min a year ago or so but yeah this could be big. Once could use this for a nice little easy framework for LE. Only sending string data seems like it won't be the most efficient but should be good enough for a lot of apps. Quote Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 24, 2015 Author Share Posted February 24, 2015 Yeah. I agree it'd be really good to get this DLL module working. That would be so helpful if you could find the time to throw a little example together for me. Thanks! Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Rick Posted February 24, 2015 Share Posted February 24, 2015 OK Guppy was right, you need to link vs source. If you do source you'll end up eventually with an error message talking about multiple VM's. So what I did was create an empty DLL project. In project properties link against E:\Steam\steamapps\common\Leadwerks Indie Edition\Library\Windows\x86\lua51.lib and include header path E:\Steam\steamapps\common\Leadwerks Indie Edition\Include\Libraries\lua-5.1.4. Note these are probably different on your system but this is just where your LE engine is installed. Make sure you put dbl quotes around the entire path in VS when you are adding these locations. Then I tested with the following code and it worked. #define DLL_EXPORT extern "C" __declspec(dllexport) extern "C"{ #include "lua.h" #include "lauxlib.h" #include "lualib.h" } #define PI (3.14159265358979323846) static int miles_to_km(lua_State *L) { double miles = luaL_checknumber(L, 1); double km = miles * 1.609; lua_pushnumber(L, km); return 1; /* one result */ } /* end of miles_to_km */ static int circle_calcs(lua_State *L) { double radius = luaL_checknumber(L, 1); double circumference = radius * 2 * PI; double area = PI * radius * radius; lua_pushnumber(L, circumference); lua_pushnumber(L, area); return 2; /* one result */ } /* end of miles_to_km */ static const luaL_Reg testlib[] = { { "miles_to_km", miles_to_km }, { "circle_calcs", circle_calcs }, { NULL, NULL } }; /* ** Open msg library */ DLL_EXPORT int luaopen_msglib(lua_State *L) { luaL_openlib(L, "test", testlib, 0); return 1; } In App:Start() -- load our custom DLL package.loadlib("LuaDLLTest.dll", "luaopen_msglib")() System:Print(test.miles_to_km(40)) Sorry about going down the adding source instead of linking. I swear I did that before but I guess I was wrong. Wouldn't be the first time. The main issue between source vs linking is this Lua VM. Since when you link you share the lua51.dll VM I guess vs when you add the lua source to your DLL the lua51.dll and your DLL now have 2 VM's created and lua doesn't like that. Quote Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 24, 2015 Author Share Posted February 24, 2015 Thanks for putting this together for me! I did a search for lua51.lib" and I don't have that file on my computer. lol I'll go through this tomorrow though. Thanks again! Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Rick Posted February 24, 2015 Share Posted February 24, 2015 Right click on Leadwerks Game Engine in steam and click properties. Then go to Local Files tab and click Browse Local Files button. This will bring you to the LE steam files. This is the locations I'm talking about with the Library and Include paths. Quote Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 24, 2015 Author Share Posted February 24, 2015 I know, but I don't have those folders there. I have the Lua header files here: "C:\Leadwerks\Engine\Source\Libraries\lua-5.1.4" (from a previous install - demo from 2.x I think), but there's no lua.lib file anywhere on my computer. I ran a full search for that, and also searched for all *.lib files in my Leadwerks directories with no luck. Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Rick Posted February 24, 2015 Share Posted February 24, 2015 You have the steam version of LE right? I'm surprised steam installed it right of C drive. Something isn't right with that. What is different about your setup? Quote Link to comment Share on other sites More sharing options...
shadmar Posted February 24, 2015 Share Posted February 24, 2015 Should be about here : C:\Program Files (x86)\Steam\SteamApps\common\Leadwerks Game Engine\Library\Windows\x86\lua51.lib But could be that is only included with the std ed? Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB Link to comment Share on other sites More sharing options...
Aaron Symons Posted February 24, 2015 Author Share Posted February 24, 2015 Sorry, I meant to say that the only Lua headers I have are included in an old install of LE before it went on Steam. My Steam version doesn't have the Include and Library paths, but the install does exist in SteamApps, as you mention. Should be about here : C:\Program Files (x86)\Steam\SteamApps\common\Leadwerks Game Engine\Library\Windows\x86\lua51.lib But could be that is only included with the std ed? That's what I'm thinking. Quote Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660 Link to comment Share on other sites More sharing options...
Recommended Posts
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.