0

I am beginner in LUA. I have written the following code in lua file that mysql proxy run with it.

function read_query(packet)
    if string.byte(packet) == proxy.COM_QUERY then
        local command = string.lower(packet)
        if string.find(command, "select") ~= nil and string.find(string.lower(packet), "from") ~= nil then
            local socket = require('socket')
            local conn, err = socket.connect('localhost', 5050)
            print(conn, err)
            proxy.response.type = proxy.MYSQLD_PACKET_OK
            //proxy.response.resultset get json from web service (url)
            proxy.response.resultset = {
                fields = {
                    { type = proxy.MYSQL_TYPE_INT, name = "id", },
                },
                rows = {
                    { 9001 }
                }
            }
            return proxy.PROXY_SEND_RESULT
        end
    end
end

I want to connect to the web service on Port 5050 that return the JSON file and save the json that it returns in the proxy.response.resultset. Another question, How can i add socket module. I paste files like following image

socket module files

but give an error : can not find /socket/core.lua.

Vickie Jack
  • 95
  • 1
  • 10

1 Answers1

0

local socket = require('socket')

You are using luasocket and it comes as a mix of lua (socket.lua) and binary (socket/core.so) files. You need to set (if it's not set already) to point to .so files; something like this may work: package.cpath=package.cpath..';./?.so'

Paul Kulchenko
  • 25,884
  • 3
  • 38
  • 56
  • I can not find core.so in web. and how can i store json that return from url in proxy.response.resultset? – Vickie Jack Mar 26 '18 at 21:07
  • It should be in `socket/` folder. If not, you need to compile luasocket and put it there; your directory has a number of files that came from luasocket source. You won't be able to use socket library without that binary file. – Paul Kulchenko Mar 26 '18 at 21:38