0

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.

6
  • Don't rely on the filename is the last chunk to be received. Use other methods to detect the last chunk. Commented Mar 29, 2016 at 14:36
  • @EgorSkriptunoff Noted. But the issue is that I cannot decode the chunks using Lua. I may want to run a java helper file instead. Commented Mar 29, 2016 at 14:53
  • @warspyking LuaJ is used to run Lua scripts inside Java files. But how about running Java functions inside Lua files? Commented Mar 29, 2016 at 14:56
  • To decode the chunks using Lua, you have to know incoming data format. It is enough to write decoder in any programming language. Commented Mar 29, 2016 at 15:00
  • @EgorSkriptunoff I know the format of the chunks. But I do not know to decode chunks created by java to Lua and I don't have the resources to follow. Commented Mar 29, 2016 at 15:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.