Obito
Obito

Reputation: 77

Load java function in Lua

Simple QUESTION : Are there ways to run or load java functions inside Lua?

I am trying to create a phone application that transfers files between server and client using Lua. The server uses Java while client uses Lua.

this is a lua function that receives file

function UDPClientModule.receiveFile()
    local data, status
    local chunks = {}
    while true do
        data, status = udp:receive()
        print("status: ", status)
        if data ~= nil then
            table.insert(chunks, data)
            --the filename is the last chunk to be received
            if string.match(data, ".jpg") then
                -- but strangely returns true 
                break
            end
        end
        socket.sleep(0.5)
    end
    --combineAndOpenImage(t)
end

No problems so far. However, the chunks sent by the server are encapsulated in a class like this:

public class FileChunk {
    private List<Data> dataList; 
    //functions below
}
public class Data{
    private byte[] fileData;
    // functions and adding file headers below
} // then UDPServer.java sends bytes of FileChunk

Because of this, packets received by the lua function are strange which also results in string.match(data, ".jpg") returning true. So I want to run java files (eg. UDPClient.java) in order to receive and decipher the chunks, instead of lua.

I don't want to change the server nor migrate the client language to java. I haven't found any resources about this so I need help.

Upvotes: 0

Views: 256

Answers (1)

RyanSquared
RyanSquared

Reputation: 148

You would need to create a wrapper library, such as the ones in C. I do not know how, but I hope this provides you a sense of direction.

Upvotes: 1

Related Questions