Closed TechStudent10 closed 1 year ago
Yes, take a look on the readme for an example
Where? There is no example of this on the README.
Where? There is no example of this on the README.
Not exactly converting a JS object to a table, but it's the same concept of the example on the readme:
lua.global.set('window', window) // Converting the engire window object to a lua table
const luaWindow = lua.global.get('window') // Convert the window lua table to a JS object
Where? There is no example of this on the README.
Not exactly converting a JS object to a table, but it's the same concept of the example on the readme:
lua.global.set('window', window) // Converting the engire window object to a lua table const luaWindow = lua.global.get('window') // Convert the window lua table to a JS object
Ah sorry. I mean returning a JavaScript object in a Lua function.
I have this (Lua) code:
element = getElement("Text0")
getElement
returns a JavaScript object in JavaScript, but I need it to be a Lua table.
I don't understand exactly what you want. Can you make a minimal repro?
@ceifa (sorry if something is wrong I'm currently on my phone)
import { LuaFactory } from "wasmoon"
const factory = new LuaFactory()
const lua = factory.createEngine()
lua.global.set("getObject", () => {
return {hello: "world"}
}
await lua.doString(`
obj = getObject()
print(obj)
`)
The output should be {"hello": "world"}
, but it is instead nil
.
Tested the exactly same code and it works: https://codesandbox.io/s/cold-http-gxe4yi?file=/src/index.js
Oh gosh I'm dumb :/
I put the return
statement in another set of parenthesis. Sorry for wasting your time on a dumb mistake :/
Is there a way to convert a JavaScript object (that also contains other objects) to a Lua table?
When I attempt to do this myself by having a function that returns a JS object, Lua assigns it
nil