LuaJS icon indicating copy to clipboard operation
LuaJS copied to clipboard

Redirecting stdout

Open Frityet opened this issue 1 year ago • 0 comments

I am trying to redirect stdout to a <pre>, so I did

    const handleExecute = async () => {
        setOutput('')
        try {
            const lua = await getLuaState()
            const _G = lua.getGlobalTable()
            // const io = _G.get('io') as LuaTable
            _G.set('print', (args: any) => {
                console.log({ args })
                setOutput((prev) => prev + args + '\n')
                console.log("print(): " + args)
            })
            await lua.run(code);
        } catch (error: any) {
            setOutput("Error: " + error.message)
        }
    }

however args seems to be undefined for any input

Frityet avatar Oct 23 '24 22:10 Frityet