[Home] [Downloads] [Search] [Help/forum]

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  loadlib error
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

loadlib error

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Wayen   China  (17 posts)  [Biography] bio
Date Sun 28 May 2017 08:53 AM (UTC)
Message
Today,I test the code which use mysql database , the code is :
-- load the MySQL dll
loadlib ("mysql.dll", "luaopen_luasqlmysql") ()

-- create environment object
env = assert (luasql.mysql())

-- connect to data source
con = assert (env:connect ("databasename", "username", "password", "servername"))

-- empty our table
res = con:execute"DROP TABLE players"

res = assert (con:execute[[
CREATE TABLE players(
name varchar(50),
class varchar(50)
)
]])


-- add a few elements
list = {
{ name="Nick Gammon", class="mage", },
{ name="David Haley", class="warrior", },
{ name="Shadowfyr", class="priest", },
}

for i, p in pairs (list) do
res = assert (con:execute(string.format([[
INSERT INTO players
VALUES ('%s', '%s')]], p.name, p.class)
))
end

-- retrieve a cursor
cur = assert (con:execute ("SELECT * from players" ))

-- print all rows, the rows will be indexed by field names
row = cur:fetch ({}, "a")

while row do
print ("\n------ new row ---------\n")
table.foreach (row, print)

-- reusing the table of results
row = cur:fetch (row, "a")
end

-- close everything
cur:close()
con:close()
env:close()

=========================================================

Then when I run the script , A error occur:

[string "Script file"]:2: attempt to call global 'loadlib' (a nil value)
stack traceback:
[string "Script file"]:2: in main chunk

So I don't think this code is error but maybe my system setting is not correct ?
[Go to top] top

Posted by Fiendish   USA  (1,641 posts)  [Biography] bio   Global Moderator
Date Reply #1 on Sun 28 May 2017 09:01 AM (UTC)
Message
You want package.loadlib instead

https://www.mushclient.com/scripts/doc.php?lua=package.loadlib

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Wayen   China  (17 posts)  [Biography] bio
Date Reply #2 on Sun 28 May 2017 01:21 PM (UTC)

Amended on Sun 28 May 2017 02:25 PM (UTC) by Wayen

Message
I replace the code use this to test the loadlib:

assert(package.loadlib ("mysql.dll", "luaopen_luasqlmysql")) ()


the old error is disappear .But new error occur :

The specified precedure could not be found .


===========================================================


Then I use dependency waler to check and updated one place:

assert(package.loadlib ("mysql.dll", "luaopen_luasql_mysql")) ()

add a "_"

Now it is correct and not error.
[Go to top] 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.


1,147 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]