Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion Goto page 1, 2  Next
emnaki
Wanderer


Joined: 12 May 2007
Posts: 59

PostPosted: Mon Dec 31, 2007 6:14 pm   

LUA require help with LuaSQL
 
I'm trying to use to use LuaSQL to access my MYSQL database since it looks cleaner than my current ZScript implementation. But I've been unable to import the dll mysql.dll using
Code:
require("luasql.mysql")

It tells me that LIBMSQL.dll is not found and to reinstall the application. But the file is right there in my LUA_CPATH. I'm like a total LUA newbie though I've read the book in the web. Could a LUA guru please help, tell me how you managed to import mysql.dll. thanks.

EDIT: Just wanted to add that the require statement works in the offical Lua 5.1 interactive shell
Reply with quote
rck
Novice


Joined: 26 Oct 2005
Posts: 32
Location: California

PostPosted: Mon Dec 31, 2007 7:49 pm   
 
You mention mysql.dll but it's asking for libmysql.dll, note the difference?

Also, if you do have those files, I'd say try dropping them into the CMUD directory.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Mon Dec 31, 2007 7:58 pm   
 
put the libmysql.dll in the cmud directory or add the LUA_CPATH directory to your system's PATH variable.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
emnaki
Wanderer


Joined: 12 May 2007
Posts: 59

PostPosted: Tue Jan 01, 2008 2:45 am   
 
Thanks, problem is solved by putting the file in my CMUD directory. I foresee I'll have a lot more Lua questions in the future.
Reply with quote
emnaki
Wanderer


Joined: 12 May 2007
Posts: 59

PostPosted: Tue Jan 01, 2008 2:55 am   
 
Dharkael wrote:
put the libmysql.dll in the cmud directory or add the LUA_CPATH directory to your system's PATH variable.

Another question, how to you add the LUA_CPATH to PATH? just appending ;%LUA_CPATH% to the end of PATH does not appear to work. I foresee the CMUD directory getting really messy if I have to dump all the LUA dlls there.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Tue Jan 01, 2008 4:13 pm   
 
You have to create the LUA_CPATH variable before you can add it to the path.

The LUA_CPATH variable should have the C:\location\LUA_StuffIshere value.
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed Jan 02, 2008 11:26 am   
 
Actually the LUA_PATH and LUA_CPATH variables should not just point to the relevant directories.
Lua uses a special syntax to turn the LUA_PATH/LUA_CPATH variables and the name passed to the require function to find and load the files.
Read about it here and here.
Emnaki, I was suggesting actually adding the C:\blah\blah\lua_c or whatever the path is into your PATH variable.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Thu Jan 31, 2008 8:36 am   
 
So do we have a set of instructions on getting this working anywhere? I'm rather interested in this, and want to know what i have to download, from where, and where i have to put it. An basic example script would come in useful too. Yaya, i know, just hand it to me on a platter why dont you! ;)
_________________
The Drake Forestseer
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Thu Jan 31, 2008 9:42 am   
 
Ok, so i've got it working now, but next step is, what am i doing wrong in the following code that is preventing it from allowing me from accessing all the returned columns?
Code:
--Include The LUASQL DLL
require("luasql.mysql")
--Reference A LUASQL MYSQL Object
env = assert(luasql.mysql())
--Connect To The Database
con = assert(env:connect("soem_baal", "root", "password", "localhost"))
--Insert A Row
--res = assert (con:execute"INSERT INTO `users` VALUES ('test', 'pwd', 'email', 8, 1, 0)")
--Execute A Select Query - Note: ATM, I'm Only Able To Retrieve The First Column Into The Cursor Variable
cur = assert(con:execute("SELECT `username`, `password` FROM `users`"))

--Fetch The Results
row = cur:fetch(row, "a")

--Print The Number Of Results
print(cur:numrows())

--Print The Column Names
print(cur:getcolnames())

--Loop Through The Results
while row do
  --Display The Results
  print(row)
  --Fetch The Results
  row = cur:fetch(row, "a")
end

--Close Our Cursor
cur:close()
--Close The Connection
con:close()
--Close The MYSQL Object
env:close()


Results in

Code:

3
{"username", "password"}
Forestseer
guest
test


Oh, i tried row.username, row['username'], row.1, row[1] (the last 2 with the second param of fetch set to "n") and those all either result in a bug, or nil :(
_________________
The Drake Forestseer
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Jan 31, 2008 1:52 pm   
 
Okay In your first cur:fetch call you pass a nonexist(nil) value as the first argument,
Code:
--Fetch The Results
row = cur:fetch(row, "a")

In your first cur:fetch call the variable row doesn't exist yet so evals to nil when what you really wanted was to pass a table.
change the first cur:fetch to
Code:
--Fetch The Results
row = cur:fetch({}, "a")

On the following calls to cur:fetch (the ones in while loop) you're correct in reusing the row variable as the first argument to fetch (row exists at this time and correctly points to a table)

Anyways row.username and row.password or row['username'] , row['password'] should work as expected.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Thu Jan 31, 2008 11:32 pm   
 
it throws an error when i use that syntax, passing the nill value row was the only way i could get it to work :(

Code:

Access violation at address 057DV58B in module 'lua5.1.dll'. Write address of 04A47478.
_________________
The Drake Forestseer
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Feb 01, 2008 1:30 am   
 
Lame.
I found a thread on lua-users list that seems to relate to this.
What version of luasql.mysql are you using?
Did you get it from the luaforge site?
Did you compile it yourself or download a precompiled version?
Are you using the lua.dll that came with CMUD or did you compile your own or get it from somewhere else?
It's looking for lua5.1.dll but CMUD lua ships with a lua.dll did you add a lua5.1.dll(if so from where)?
I'm sorry to ask so many questions but if you let me know I might be able to rundown a permanent resolution for you.

Anyways from what I garner a temp fix is to pass in a non empty table to the first cur:fetch ala
Code:
local row = cur:fetch({1},"a")

Since I can't reproduce your error I cant test its effectiveness.
Also if that doesn't work you could try using this format.
Code:
for i=1,cur:numrows() do
   local name,pass =cur:fetch()
   print (name,pass)   
end
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Fri Feb 01, 2008 1:43 am   
 
i got lua5.1.dll from the lua site (originally got the one from mush, then tried the 64bit version from lua, it failed even worse, so went back to 32bit version)
i got luasql.mysql from the luaforge site, whatever the newest precompiled version is

i just tried your {1}, and it failed,

i tried the for loop version, and it worked :D
yay :)
_________________
The Drake Forestseer
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Feb 01, 2008 2:27 am   
 
Okay I think a major part of the problem is that basically you're loading two lua interpreters the lua.dll that comes with CMUD loads and the lua5.1.dll that you downloaded from elsewhere.
Depending on how a lua library is built it can be looking for a specifically named dll ie lua5.1.dll so that either fails if no such dll is found or if that dll is found its not going to be the same one that CMUD
is using since that dll is called lua.dll. I ran into this problem when I first started using lua in CMUD this can be fixed by making something called a forwarding dll that basically creates a dll called lua5.1.dl
that forwards all calls it recieved to the lua.dll so that everything is running in the same lua interpreter.
I give a description on how to fix it here but it takes a bit of effort.

Anyways on my system I didn't couldn't get it to happen cuz I had previously fixed that problem.
I was however able to reproduce your issue by simply renaming my forwarding dll and downloading a lua5.1.dll from the luaforges site.
So the perm fix seems to be to create that forwarding dll (which if you continue to use other lua libraries in the future will save you much headache)
But if not it seems you can work around using
Code:
row = cur:fetch({test="something"},"a")

The table has to contain a key-value pair.
This seems to do the trick, but I can't speak to what other subtle crud might pop up later.
Recommend you give trying to add the forwarding dll a try at some point.

Maybe Zugg can create a forwarding dll and post it as a seperate download, that could probably save the lua users a lot of problems.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Fri Feb 01, 2008 3:20 am   
 
And you posted this dll in a zip file on WHICH server? *inno*
_________________
The Drake Forestseer
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Fri Feb 01, 2008 3:33 am   
 
Ok, turns out, LUA have already provided a compiled version of this DLL on their site, with a slightly different name.
Now, listen carefully here, because i actually replace a cMUD dll in the following batch of instructions:

Code:

WITH CMUD CLOSED

Step 1. Download the file lua5_1_2_Win32_dll8_lib.zip from http://luabinaries.luaforge.net/download.html
Step 2. Extract the following DLLs into your cmud directory
           lua51.dll
           lua5.1.dll
Step 3. Rename lua.dll to lua.old
Step 4. Rename lua51.dll to lua.dll
Step 5. Extract the lua51.dll to your cmud directory again (just incase any other lua stuff references this dll in future)

OPEN CMUD


If all went well, you shouldn't notice any differences in cmud other than the fact that some bugs are now fixed.
If it didnt go so well, delete the lua dll files, and rename lua.old back to lua.dll

Perhaps zugg can ship with these modifications in the next build? *inno*
_________________
The Drake Forestseer
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Feb 01, 2008 10:06 am   
 
When I tried that I get 2 error messages that say
Quote:
This application has failed to start because MSVCR80.dll was not found. Re-installing the applications may fix this problem.

Then when CMUD lua has not been loaded, there is no option to use lua as a scripting language.



Oh and I never uploaded the dll anywhere for anyone to DL cuz I never expected people to download a DLL that I made.
Thats why I provided instructions on how to make it.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Fri Feb 01, 2008 5:41 pm   
 
If someone can verify what the correct name of the Lua DLL *should* be, then I can easily change this in CMUD and distribute the correct DLL. My question is whether it should be named LUA51.DLL or LUA5.1.DLL...which is correct?
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Feb 01, 2008 7:05 pm   
 
Well the link from lua.org to download the binaries points to http://luabinaries.luaforge.net/ and they use lua5.1.dll
They also provide a forwarding dll called lua51.dll that forwards calls for lua51.dll to the lua51.1.dll
And when you're downloading most lua third party libraries they speak of being compatible with Luabinaries
So I would think lua5.1.dll is the way to go.
It's not to say you'll never find something looking for another name, but Luabinaries seems to be the unofficial standard.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Fri Feb 01, 2008 7:16 pm   
 
Nobody seems able to agree on what the proper dll name should be. I've seen libraries that require lua.dll, lua5.1.dll, lua51.dll, lua5.1.1.dll, etc etc etc.
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Sat Feb 02, 2008 2:09 am   
 
If you ship with the forwarding DLLs aswell, then there will be no hassles? That's the way i see it anyways :)
_________________
The Drake Forestseer
Reply with quote
emnaki
Wanderer


Joined: 12 May 2007
Posts: 59

PostPosted: Sun May 25, 2008 8:19 am   
 
Looks like I've gone the full circle, I recently reinstalled my com, and tried to get luasql to work with:

Code:

require("luasql.mysql")


And now I've been greeted with the error:

error loading module 'luasql.mysql' from file '.\luasql\mysql.dll': The specified procedure coud not be found. Crying or Very sad

Does anyone know what is wrong?
Better still could anyone give a step by step solution from a clean install of CMud 2.25 on how to get the require("luasql.mysql") statement to work?
Reply with quote
alluran
Adept


Joined: 14 Sep 2005
Posts: 223
Location: Sydney, Australia

PostPosted: Sun May 25, 2008 9:26 am   
 
Did you replace the lua dlls? bet you didn't. I can probably track down the package I put together somewhere to replace the existing DLLs. Perhaps Zugg can give a confirmation on wether he's thinking of including these forwarding DLLs or not?
_________________
The Drake Forestseer
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun May 25, 2008 12:26 pm   
 
As previously suggested I uploaded a zip file containing two forwarding dll's lua50.dll and lua5.1.dll both of which foward to CMUD's native lua.dll
It be found here http://www.megaupload.com/?d=U1QCC0NF
Just unzip these in the same directory that CMUD.exe and lua.dll is found.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Sun May 25, 2008 6:12 pm   
 
emnaki wrote:
Looks like I've gone the full circle, I recently reinstalled my com, and tried to get luasql to work with:

Code:

require("luasql.mysql")


And now I've been greeted with the error:

error loading module 'luasql.mysql' from file '.\luasql\mysql.dll': The specified procedure coud not be found. Crying or Very sad

Does anyone know what is wrong?
Better still could anyone give a step by step solution from a clean install of CMud 2.25 on how to get the require("luasql.mysql") statement to work?


In my CMUD install dir(the one with CMUD.exe) I have the two forwarding dll's lua50.dll and lua5.1.dll from the zip file from the above post.
In my CMUD install dir I have two folders lua and lua_c.
I have a system variable named CMUD_PATH that points to my CMUD install dir:
Code:
C:\Program Files\CMUD

I have another system variable called LUA_CPATH that contains:
Code:
?;?.dll;%CMUD_PATH%\lua_c\?.dll;%CMUD_PATH%\lua_c\?

And the last system variable called LUA_PATH that contains:
Code:
?;?.lua;%CMUD_PATH%\lua\?.lua;%CMUD_PATH%\lua\?\?.lua


That's my basic CMUD Lua setup.
To get luasql.mysql working:
Go to this site http://luaforge.net/frs/?group_id=12
Download this file luasql-2.1.1-mysql50-win32-lua51.zip
From this file and into your lua_c directory put the libmysql.dll and the luasql folder(the one containing mysql.dll)


require("luasql.mysql") should work now.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net