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
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Aug 11, 2008 4:06 pm   

Feature Request -- Allow LuaSQL for SQL
 
Hey Zugg,

When you get a chance, with your copious amounts of free time Laughing, can you compare you version of sqlite3.dll with that distributed by the LuaSQL group. I'd like to be able to load sqlite3 db functionality in lua via the require command. e.g.
Code:
require "sqlite3"


As it stands, what I had to do was create a subdirectory under the CMUD install directory called 'luasql' and put the LUASQL version of the sqlite3.dll there. After that I was able to successfully (at least it seemed to be successful, still early in the testing) run the follow require statement
Code:
require "luasql.sqlite3"


Now I realize this may not be possible considering your time and the how you use the sqlite3.dll. I also realize this may all be moot considering the pending database module rewrite. However it would be really nice to be able to create proper SQL databases using the SQLite functionality with a standard CMUD install. It's probably the approach you were planning on for the database module rewrite, and if not it would make for a great and powerful (albeit GUI-less) alternative.[/code]
_________________
Asati di tempari!
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Tue Aug 12, 2008 3:47 am   
 
OHHH that would be nice, I tried to do that but ran into problems, some difference between lua compiled with debug/no debug options(read here). And at that point I had considered asking that... but i'ld hate to distract from the mapper re-write.. unless implementing a sqlite database interface would be... easy while Zugg is mukking about in the database rewrite portion.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Tue Aug 12, 2008 5:20 am   
 
Where did you download you luasql for sqllite from? Mine worked just fine and I got it from here
_________________
Asati di tempari!
Reply with quote
Zugg
MASTER


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

PostPosted: Tue Aug 12, 2008 4:48 pm   
 
I don't build the sqlite (or lua) dlls myself. I forget where I got the sqlite3.dll file, but I'm pretty sure it was from the main sqlite distribution site. Have you tried just replacing the sqlite3.dll file in your CMUD directory with the one that you want to see if it works?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Fri Aug 15, 2008 5:43 pm   
 
Yes I did and it crapped out, I think you need a version that has the lua hooks in it for the require statement to work. I'm not sure if that breaks anything you do.

I tried replacing the version you have with the version I downloaded from the luasql site and CMUD had trouble loading the cmd.db... probably a different namespace or something.

I'm making progress though... using my setup I'm able to create db file and create tables within them. The one drawback is that it creates the db file in the CMUD directory. I'll have to dig to see how I can reference the My Games\CMUD folder.
_________________
Asati di tempari!
Reply with quote
Zugg
MASTER


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

PostPosted: Sat Aug 16, 2008 12:26 am   
 
Do the people on the luasql site talk about this and what specific changes they have made to the DLL? If you can't load the cmd.db file with their DLL, then it sounds like they made some serious changes. Not sure what to suggest, but I obviously won't ship the luasql replacement if it prevents the cmd.db file from loading.

In case you need to test it, the cmd.db and the cmudhelp.db files are the two v3 SQLite files. *.pkg files are still v2 SQLite files. So CMUD is currently uses both database versions.
Reply with quote
wrym
Magician


Joined: 06 Jul 2007
Posts: 349
Location: The big palace, My own lil world

PostPosted: Sat Aug 16, 2008 3:07 am   
 
Luasql.sqlite3 is 372kb where as the compiled sqlite3 from sqlite.org is 380kb and obviously is set up to support a lua interface instead of the standard interface, since the luasql.sqlite3 is smaller, i'ld say something was removed/changed and not just added lua capabilities, but I've no clue...

As for my problems, I ran across luasql.sqlite3, lsqlite3 lua-sqlite3 a lsqlite (2.8.x that had different interface)... deleted them all and downloaded just the luasql.sqlite3 from luaforge... however I tend to learn by example.. and find the lack of luasql.sqlite3 examples... and even documentation? (although it looks like it just follows the documentation from sqlite.org) extremely anoying.

Tech you have any code, or examples you've found that you care to share?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sat Aug 16, 2008 5:11 am   
 
Here's the documentation I've been using

http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html
http://luasqlite.luaforge.net/lsqlite3.html
http://www.keplerproject.org/luasql/manual.html#introduction (This one is where I started)
http://www.keplerproject.org/luasql/examples.html

http://www.sqlite.org/docs.html
http://www.sqlite.org/omitted.html
http://www.sqlite.org/cvstrac/wiki?p=ForeignKeyTriggers
http://www.rcs-comp.com/site/index.php/view/Utilities-SQLite_foreign_key_trigger_generator

I sort of piece-mealed it together and used what I already know of Lua and SQL and programming in general.

I've been kicking around the idea of building on Fang's documentation for Lua, adding something for functions and possibly another how to guide for Lua SQL. It'll be a while since there a long to do list. Smile

As for code, here are the 3 aliases I'm using now. i basically load the environment, connect to a DB, then create some tables and finally close the DB.

Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <alias name="createdb" copy="yes">
    <value>sql = {
  "CREATE TABLE Portfolio ( portfolio_id INTEGER UNIQUE PRIMARY KEY, owner_id INTEGER NOT NULL, name VARCHAR(32), description VARCHAR(255));",

"CREATE TABLE PurchaseHistory ( purchase_id INTEGER UNIQUE PRIMARY KEY, amount INTEGER NOT NULL, type CHAR(4) NOT NULL, price_id INTEGER NOT NULL, port_stock_id INTEGER NOT NULL);",
 
"CREATE TABLE PortfolioStock ( port_stock_id INTEGER UNIQUE PRIMARY KEY, portfolio_id INTEGER NOT NULL, stock_id INTEGER NOT NULL, amount_held FLOAT(10) NOT NULL, description VARCHAR(255) NOT NULL);",


"CREATE TABLE PriceHistory ( price_id INTEGER UNIQUE PRIMARY KEY, date DATE NOT NULL, price FLOAT(10) NOT NULL, stock_id INTEGER NOT NULL);",

"CREATE TABLE Stock (stock_id INTEGER UNIQUE PRIMARY KEY, name VARCHAR(64) UNIQUE NOT NULL, description VARCHAR(255), type VARCHAR(16) NOT NULL, founded DATE, bankrupt DATE);",

"CREATE TABLE Owner ( owner_id INTEGER UNIQUE PRIMARY KEY, name VARCHAR(64) NOT NULL, description VARCHAR(255), mud VARCHAR(64) NOT NULL);"
}
conn = env:connect("test.db")
for i,v in pairs(sql) do
  debug(conn:execute( v ) )
end
</value>
  </alias>
  <alias name="c2db" copy="yes">
    <value>--Include The LUASQL DLL
--require("luasql.sqlite")
--Reference A LUASQL MYSQL Object
--env = assert(luasql.sqlite())

function debug (stmt, msg)

  if (debugVar) then
    print (stmt, msg)
  end
end

debugVar = 1
require "luasql.sqlite3"
env = assert(luasql.sqlite3())
debug(env)

dbName = "test.db"
if zs.numparam ~= 0 then
  dbName = zs.param(1)
end
debug("The target database is " .. dbName)
conn = assert(env:connect(dbName))

debug (conn)

</value>
    <arglist>$dbName</arglist>
  </alias>
  <alias name="closedb" copy="yes">
    <value>
debug(conn:close());

debug(env:close());</value>
  </alias>
</cmud>



Getting the thread back on track, I guess I will live with it as it is. It's really only an interim approach until the DB module is rewritten which will probably do the same or more with a nice interface. Plus the instructions aren't that complex, so those who really want to use it before hand, should be able to.
_________________
Asati di tempari!
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Fri Apr 17, 2009 8:42 pm   
 
How would I output something with ansi to the screen from an alias written in LUA

ive tried:

print(string.format("%s num %s Equip", zs.func.ansi(high,red,under), zs.func.ansi(high,magenta,under)))

I am lost on what to do, I cant find any documentation on how to do this correctly, but im still looking.

EDIT:
AH-HA! I kept thinking and thinking and thinking and remembered that the cmud display displays many html tags so I tried that and BAM! worked like a charm.

print("<font color=#008000>Your green text goes here.</font>")
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Fri Apr 17, 2009 11:13 pm   
 
I am really considering releasing my entire eqdb script once its finished... I think it would be a good learning tool for those that learn by example. I may actually just release most of my scripts and put them on my website. HAHA this of coarse means that I will have to go back and add some comments on what does what.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Apr 17, 2009 11:16 pm   
 
I am going to guess the size difference between the 2 is due to compiler optimisations, and small changes in the export/import tables. The likely reason that the Lua version won't work as the sqlite3.dll for CMud is that the number of parameters for the functions are changed, and nearly all would have a LuaWorkspace as thier first parameter.

When I have some more free time I will see if I can put together some code Zugg could add to CMud to permit Lua to access and use the sqlite3.dll that CMud already has loaded. If I can figure it out correctly then I will make code for either the pcre.dll or some of the mid-level interface to be available as well.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Fri Apr 24, 2009 12:08 am   
 
I am trying to enable or disable a class from a trigger with Lua as the selected type of code, with zscript it was #T- classname or #T+ classname to enable or disable a class.

I believe this is the only documenation on it http://forums.zuggsoft.com/modules/mx_kb/kb.php?page=3&mode=doc&k=2987 and I have tried using the zs object a couple of different ways but Its just not working and I think I must be getting the syntax wrong.
Reply with quote
Fang Xianfu
GURU


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

PostPosted: Fri Apr 24, 2009 3:10 am   
 
zs["t+"]("trigger id")

You could also use zs.gettrigger("trigger id") to return the object (and optionally save it somewhere, if you want to) and then edit its enable property directly, either:

zs.gettrigger("trigger id").enabled = false

or

trig = zs.gettrigger("trigger id")
trig.enabled = false
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
xekon
Apprentice


Joined: 11 Oct 2007
Posts: 154

PostPosted: Fri Apr 24, 2009 9:29 pm   
 
Thanks for the help, have my project nearly completed now! Will probably have it finished some time today.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
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