Last active
September 21, 2017 21:50
-
-
Save cristiano-belloni/5a7a78062e2f986bd41045248c47c2f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
Author
cristiano-belloni
commented
Sep 21, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment