Include MySQL
#21
I found a binary installer for luarocks for windows, installed it normally, from MSVC's command prompt (so that it can find the compiler).

How did you install for linux, did you use a specific luarocks package, or did you build from source? If building yourself, you might need to modify Lua compilation to support dynamic libraries.

I wonder now, maybe we broke something in MCServer linux compilation and it doesn't support dynamic libraries in its Lua engine anymore. I'll check this out.
Reply
Thanks given by:
#22
(01-09-2014, 05:46 AM)xoft Wrote: I found a binary installer for luarocks for windows, installed it normally, from MSVC's command prompt (so that it can find the compiler).

How did you install for linux, did you use a specific luarocks package, or did you build from source? If building yourself, you might need to modify Lua compilation to support dynamic libraries.

I wonder now, maybe we broke something in MCServer linux compilation and it doesn't support dynamic libraries in its Lua engine anymore. I'll check this out.

Okey, tomorrow i will watch for a installer.
I used the Quickstart from there: http://luarocks.org/en/Installation_inst...s_for_Unix

Okey maybe its broken.. or a fail from me
Reply
Thanks given by:
#23
You're right, the Lua compilation has been butchered. Working on it now.

Please try out the LuaDlFix branch, it should provide a fix for *nix versions.
Reply
Thanks given by:
#24
(01-09-2014, 04:51 PM)xoft Wrote: You're right, the Lua compilation has been butchered. Working on it now.

Please try out the LuaDlFix branch, it should provide a fix for *nix versions.

Thanks now MCServer find luasql.

Current error:
[16:34:11] LUA: 2 - Plugins/Permissions/onlogin.lua:5: attempt to index global 'luasql' (a nil value)
[16:34:11] Error in plugin Permissions calling function <callback>()

Code:
function OnPlayerJoined(Player)
    -- load driver
    require "luasql.mysql"
    -- create environment object
    env = assert (luasql.mysql())
    -- connect to data source
    con = assert (env:connect("luasql-test"))
    
end

I need to define luasql but how? Do you know this?
Reply
Thanks given by:
#25
I *think* you need to do:
local luasql = require ("luasql.mysql");  -- Put the loaded library in the variable
local env = assert(luasql.mysql());  -- Use that variable to access the library

Don't forget to use "local" whenever possible, you don't want to pollute the global namespace too much. Also "local" has faster access than global.

When pasting code in the forum, you can use [ shcode=lua ] code [ /shcode ] (without the spaces around brackets) to have the code syntax-highlighted.
Reply
Thanks given by:
#26
(01-10-2014, 06:59 AM)xoft Wrote: I *think* you need to do:
local luasql = require ("luasql.mysql");  -- Put the loaded library in the variable
local env = assert(luasql.mysql());  -- Use that variable to access the library

Don't forget to use "local" whenever possible, you don't want to pollute the global namespace too much. Also "local" has faster access than global.

When pasting code in the forum, you can use [ shcode=lua ] code [ /shcode ] (without the spaces around brackets) to have the code syntax-highlighted.

MySQL now works.
Give it a Hashmap like java for Lua? I found one on google but mcserver don't find it..
Reply
Thanks given by:
#27
I don't understand what exactly you want. If you need to store "name"="value" pairs in Lua, use a regular Lua table; internally it is a hashmap.
Reply
Thanks given by:
#28
(01-12-2014, 02:33 AM)xoft Wrote: I don't understand what exactly you want. If you need to store "name"="value" pairs in Lua, use a regular Lua table; internally it is a hashmap.

Thanks now all is working.
Now i will modify the Chat Message but on the start i become a error.

function OnPlayerChat(Player, Message)
	cRoot:BroadcastChat("<Rank : " .. Player:GetName() .. "> " .. Message);
	return true;
end

cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnPlayerChat);

Error:
Code:
[20:32:54] cPluginManager:AddHook(): bad parameters. Expected HOOK_TYPE and CallbackFunction, got TNUMBER, TNIL, TNONE. Hook not added.
[20:32:54] Stack trace:
[20:32:54]   [C](-1): AddHook
[20:32:54]   Plugins/Permissions/main.lua(14): ?
[20:32:54] Stack trace end

Can you say me what the error mean?

Edit: I saw that when a player is logging out it comes a mysql error:
Code:
[20:13:30] Error on shutting down socket 12 (192.168.178.51): 107: Transport endpoint is not connected

Login Code:
function OnPlayerJoined(Player)
	local request = assert (con:execute("SELECT rank FROM ranks WHERE name LIKE \'" .. Player:GetName() .. "\'"));
	local result = assert (request:fetch());
	
	rank[Player:GetName()] = result;
	Player:SendMessage(rank[Player:GetName()]);
	
	request:close();
end
Reply
Thanks given by:
#29
As for the first error, we just found out about some issues with Lua files being loaded in different orders. As an easy fix, make sure either:
1, The handler function and the registration are at the same file, and the handler is above the registration
2, The handler function is global in any file and the registration is done within the plugin's Initialize() function.

The error message basically tells you that you have provided wrong types of arguments - the AddHook() function was expecting a number and a function, and it got a number (TNUMBER) and a nil (TNIL). That means that the OnPlayerChat is not defined at the moment when the AddHook() function is being called.

The second error, "Transport endpoint is not connected", is a known side-effect, it is safe to ignore it (it just means that the client closed the connection before we told them that we're disconnecting). There's no harm in there.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)