I tried to just store the variable in the struct like so:
Code: Select all
ffi = require 'ffi'
socket = require("socket")
ffi.cdef[[
typedef struct {
void *Tcp;
} ClientData;
void* malloc(size_t);
void free(void*);
]]
local Tcp = socket.bind("*", 12345)
local ptr = ffi.C.malloc(ffi.sizeof("void*"))
while true do
local NewClient, Error = Tcp:accept()
if NewClient ~= nil then
local ClientData = ffi.cast("ClientData(&)", ptr)
ClientData.Tcp = NewClient
ClientData.Tcp:send("Hello World\n")
end
end
test2.lua:30: 'void *' has no member named 'send'
Can anyone help me?
And if there is no way to store a tcp client object in ffi, does anyone know of any other ways to use tcp with a lower amount of memory?
FYI, I plan on wrapping this tcp socket in a ssl connection with luasec or some other lua-based security.