First thanks for making this lib, can't really guess how I would make something like this myself.
I'm trying to add a global variable which is a table but I'm having no luck doing it.
Lua Code Example:
Trace = lua.Trace
Warn = lua.Warn
MersenneTwister = { Random=math.random, Seed=math.randomseed }
PLAYER_1 = "PlayerNumber_P1"
PLAYER_2 = "PlayerNumber_P2"
NUM_PLAYERS = #PlayerNumber
The problem I'm having is with trying to add PlayerNumber
as the file I'm executing expects it to be a defined global. It was trivial to add lua.Trace
and lua.Warn
with the documentation provided at the readme, I simply did was such bellow
const luaAdditional = new luainjs.Table({
Trace: (msg) => {
console.log(msg)
},
Warn: (msg) => {
console.warn(msg)
}
})
luaEnv.loadLib('lua', luaAdditional)
However, I can't find exactly how I could add a global table, I've tried adding it to the global variable directly such as
const globalEnv = new luainjs.Table({
PlayerNumber: new luainjs.Table({ '1': 'PlayerNumber_P1' })
})
luaEnv.loadLib('_G', globalEnv)
And it did not work, I tried looking at what the table gets transformed into lua-side and also tried this:
const globalEnv = new luainjs.Table({
keys: [1, 2],
values: ['PlayerNumber_P1', 'PlayerNumber_P2']
})
luaEnv.loadLib('PlayerNumber', globalEnv)
But whatever I added as argument to the Table method would always be inside srtValues
.
Given my failed attempts, how could I add a PlayerNumber
table as a global to the file I parse?
Here's the result I'm trying to reach: