Skip to content

Instantly share code, notes, and snippets.

@cristiano-belloni
Last active September 21, 2017 21:50
Show Gist options
  • Save cristiano-belloni/5a7a78062e2f986bd41045248c47c2f8 to your computer and use it in GitHub Desktop.
Save cristiano-belloni/5a7a78062e2f986bd41045248c47c2f8 to your computer and use it in GitHub Desktop.
global.WEB = false
const interop = require('fengari-interop')
const fengari = require('fengari')
const lua = fengari.lua
const lauxlib = fengari.lauxlib
const lualib = fengari.lualib
const luacode = `
print ('Lua: start')
js = require "js"
function printobject(o)
for k, v in pairs(o) do
print(k, v)
end
end
function foo(this, x)
printobject(x)
print(type(x))
print(#x)
end
js.global.foo = foo
`
const L = lauxlib.luaL_newstate()
/* open standard libraries */
lualib.luaL_openlibs(L)
lauxlib.luaL_requiref(L, lua.to_luastring("js"), interop.luaopen_js, 1)
lua.lua_pop(L, 1) /* remove lib */
const ok = lauxlib.luaL_dostring(L, lua.to_luastring(luacode))
if (ok) return console.log(`Error dostring: ${ok} ${lua.lua_tojsstring(L, -1)}`)
global.foo([14, 88])
@cristiano-belloni
Copy link
Author

Lua: start
0       14.0
1       88.0
userdata
/home/whatever/node_modules/fengari/src/lauxlib.js:135
    throw new Error(`PANIC: unprotected error in call to Lua API (${lua.lua_tojsstring(L, -1)})`);
    ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment