Closed Frityet closed 9 months ago
I created this wrapper
function create(type, ...args) {
return new type(...args);
}
but when I call it from lua:
local create = js.global.create
local map = create(window.Map)
console:log(map)
I get this error:
Error loading Lua script node
<script type="text/lua" src="index.lua">
Error: TypeError: type is undefined
LuaError http://127.0.0.1:8080/luajs.js:1
run http://127.0.0.1:8080/luajs.js:1
__runNode http://127.0.0.1:8080/luajs.js:1
__tryRunNode http://127.0.0.1:8080/luajs.js:1
loadDocumentScripts http://127.0.0.1:8080/luajs.js:1
enableLuaScriptTags http://127.0.0.1:8080/luajs.js:1
<anonymous> http://127.0.0.1:8080/:2
promise callback* http://127.0.0.1:8080/:2
luajs.js:1:15336
ah nvm I needed to do window:create()
@Frityet You can also already call constructors with LuaJS shims:
local map = js.global.Map:new()
js.global.console:log(map)
@Frityet You can also already call constructors with LuaJS shims:
local map = js.global.Map:new() js.global.console:log(map)
Thank you! Didn't know this, are there any more helpful utilities like that present?
Not too many, really. You can call :toTable()
on many JS objects to turn them into native Lua tables (but be careful, that can cause them to not work, depending on what they contain).
There is js.eval
(does exactly what one might think it does, avoid at all costs, eval
ruins performance) and js.await
(awaiting for async JS functions / Promises)
I get this error trying to instanciate a JS class
Of course, I can make a simple JS wrapper to get around this, but is there a better way?