Jump to content

More Precise Timer


Aaron Symons
 Share

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

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

Link to comment
Share on other sites

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

Win7 64-bit | Intel i7-3770 3.40GHz | NVIDIA GeForce GTX 660

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