![]() |
Include MySQL - Printable Version +- Cuberite Forum (https://forum.cuberite.org) +-- Forum: Cuberite (https://forum.cuberite.org/forum-4.html) +--- Forum: Development (https://forum.cuberite.org/forum-13.html) +--- Thread: Include MySQL (/thread-1305.html) |
RE: Include MySQL - xoft - 01-09-2014 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. RE: Include MySQL - daniel0916 - 01-09-2014 (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). Okey, tomorrow i will watch for a installer. I used the Quickstart from there: http://luarocks.org/en/Installation_instructions_for_Unix Okey maybe its broken.. or a fail from me RE: Include MySQL - xoft - 01-09-2014 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. RE: Include MySQL - daniel0916 - 01-10-2014 (01-09-2014, 04:51 PM)xoft Wrote: You're right, the Lua compilation has been butchered. Working on it now. 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) I need to define luasql but how? Do you know this? RE: Include MySQL - xoft - 01-10-2014 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. RE: Include MySQL - daniel0916 - 01-12-2014 (01-10-2014, 06:59 AM)xoft Wrote: I *think* you need to do: MySQL now works. Give it a Hashmap like java for Lua? I found one on google but mcserver don't find it.. RE: Include MySQL - xoft - 01-12-2014 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. RE: Include MySQL - daniel0916 - 01-12-2014 (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. 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 RE: Include MySQL - xoft - 01-12-2014 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. |