Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ Extending Lua scripting with your own code
Extending Lua scripting with your own code
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1
2
3
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #30 on Sat 09 Jan 2010 06:07 PM (UTC) |
Message
| I notice that in the first snippet, you defined LUA_API, but used LUALIB_API on the function instead. Maybe that had something to do with it? |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| Mingshao Zhang
(5 posts) Bio
|
Date
| Reply #31 on Mon 19 Sep 2011 06:25 PM (UTC) |
Message
| Hi Nick,
I tried this example but somehow i doesn't work.
I use Microsoft VC 2010 to generate the dll, I worked. But when I call it from lua executable(I use lua5.1.4 for windows), it says: nil The specified module could not be found.
Quote"This might be because you didn't put the DLL where it could be found (or the lua.dll or lualib.dll were not found either)."
I already copied the test.dll lua51.dll lua5.1.dll to the same directory as the lua executable.
Is there anything else I missed? Or is there any setting work I should do to tell lua program to find those dlls before I execute the code?
Thanks,
Mingshao | Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #32 on Mon 19 Sep 2011 11:18 PM (UTC) |
Message
| Do you have a dependency checker with Visual Studio? That usually tells you of related DLLs that might be required (some of them are a bit unexpected). |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Mingshao Zhang
(5 posts) Bio
|
Date
| Reply #33 on Tue 20 Sep 2011 04:12 PM (UTC) |
Message
| Hi Nick,
That helps a lot, Thanks, but still, the problem hasn't been solved yet.
I put test.dll into the Dependency Walker, find out all the dll that dependend,(like msvcr100d.dll ntdll.dll,etc). I copied all those dll to the same directory as lua esecutalbe is.
Still, the error messages says:
"nil The specified module could not be found.
init"
And inside the Dependency Walker, in some dll, the "Entry Point" says: "Not Bound". I don't know if that has something to do with this problem.
P.S. Lua Compiler, I use lua5.1.4 for windows, something called SciTE.
Thanks,
Mingshao | Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #34 on Tue 20 Sep 2011 11:12 PM (UTC) |
Message
| Did you read all of page 1 of this thread? You may need to put the DLL into c:\Windows or something like that.
Or you could try compiling it with Cygwin. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Mingshao Zhang
(5 posts) Bio
|
Date
| Reply #35 on Thu 22 Sep 2011 07:35 PM (UTC) |
Message
| Yes, I did read all of the page 1.
I copied all the dlls and lua executable to C:\windows\System32, and it reported the same problem. Also I copied the test.dll to MUSHclient, it print nil, too. And I want to do some pure in Windows, so I prefer not to try CYgwin.
Now I am thinking maybe the test.dll that I created is not suitable for lua5.1 to call...
#ifdef _WIN32
#define LUA_API __declspec(dllexport)
#endif
#pragma comment( lib, "lua5.1.lib" )
#pragma comment( lib, "lua51.lib" )
#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 test library
*/
LUALIB_API int luaopen_test(lua_State *L)
{
luaL_register(L, "test", testlib);
return 1;
}
about dll compiling, I use Microsoft VS2010, I added lua5.1.lib, lua51.lib to Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.
Do you think is it possible that the problem is in the test.dll? I did make a little change in the codes according the difference between lua5.0 and lua5.1.
Thanks,
Mingshao
P.S. Sorry about this looooooong message | Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #36 on Thu 22 Sep 2011 11:01 PM (UTC) |
Message
|
#pragma comment( lib, "lua5.1.lib" )
#pragma comment( lib, "lua51.lib" )
Make up your mind which one you want to use. I wouldn't use both.
Quote:
And I want to do some pure in Windows, so I prefer not to try Cygwin.
Cygwin can generate DLLs that don't rely upon any other part of Cygwin. I use that to generate the Lua DLL for inclusion in MUSHclient. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Nick Gammon
Australia (23,057 posts) Bio
Forum Administrator |
Date
| Reply #37 on Thu 22 Sep 2011 11:09 PM (UTC) |
Message
|
Mingshao Zhang said:
Now I am thinking maybe the test.dll that I created is not suitable for lua5.1 to call...
This is the sort of thing I would expect to see in the dependency walker:
Note that entry point (E symbol) giving the name of the module that you call in Lua. In this case:
assert(package.loadlib("windows_utils.dll", "luaopen_windows_utils"))()
Also note the reference to lua5.1.dll - so this is the DLL you need to have available. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Mingshao Zhang
(5 posts) Bio
|
Date
| Reply #38 on Fri 23 Sep 2011 05:24 PM (UTC) |
Message
| Thanks, Nick.
I found out my problem, when I put my test.dll into the Dependency Walker. There is no entry point.
I will try to fix this | Top |
|
Posted by
| Mingshao Zhang
(5 posts) Bio
|
Date
| Reply #39 on Sun 25 Sep 2011 08:24 PM (UTC) |
Message
| Thanks a lot, Nick
I finally make the example to work, It turns out to be that I always forgot to write the test.def file.
You have been so helpful these days, Thank you so much!!!
Mingshao Zhang | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
122,321 views.
This is page 3, subject is 3 pages long:
1
2
3
It is now over 60 days since the last post. This thread is closed.
Refresh page
top