Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Lua ➜ loadlib error

loadlib error

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


Posted by Wayen   China  (17 posts)  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 ?
Top

Posted by Fiendish   USA  (2,534 posts)  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
Top

Posted by Wayen   China  (17 posts)  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.
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.


13,720 views.

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

Go to topic:           Search the forum


[Go to top] top

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