Jump to content
Aaron Symons

More Precise Timer

Recommended Posts

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. :/

Share this post


Link to post

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

Share this post


Link to post

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;
}

Share this post


Link to post

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.

Share this post


Link to post

Okay. I've defined it, now I get: "The specified module could not be found." lol I think we're getting somewhere though. :P

 

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?

Share this post


Link to post

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.

Share this post


Link to post

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 unsure.png

 

EDIT: I may even just buy the Standard Edition of LE, especially seeing as it's on sale now. :)

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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! :D

Share this post


Link to post

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.

Share this post


Link to post

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!

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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?

Share this post


Link to post

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?

Share this post


Link to post

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. :)

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.

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.

×
×
  • Create New...