Posted 19 May 2014 - 07:44 PM
Currently, I'm working on a ComputerCraft emulator which uses LuaJ which has been driving me insane lately. So I decided to ask for help here.
I'm trying to reproduce os.loadAPI's functionality but I've had more trouble than I should have with it.
After hours I've come to the conclusion that this piece of code makes the most sense:
Which means that term.setBackgroundColour(colours.orange) would be setBackgroundColour(orange) which is not at all what I intended.
I would gladly appreciate any help with this.
I'm trying to reproduce os.loadAPI's functionality but I've had more trouble than I should have with it.
After hours I've come to the conclusion that this piece of code makes the most sense:
public void prepareAPI(IAPI api) {
String apiFile = Storage.getComputerCraftDir() + File.separator + "rom" + File.separator + "apis" + File.separator + api.getName();
System.out.println("Loading API " + apiFile);
LuaTable apiTable = LuaTable.tableOf();
LuaValue dofileEnv = m_dofile.getfenv();
m_dofile.setfenv(apiTable);
m_dofile.call(LuaString.valueOf(apiFile));
m_dofile.setfenv(dofileEnv);
m_globals.set(api.getName(), apiTable);
}
However, this seems to store the API functions inside the global table instead of the API table as I have specified with setfenv.Which means that term.setBackgroundColour(colours.orange) would be setBackgroundColour(orange) which is not at all what I intended.
I would gladly appreciate any help with this.