wasmoon 2.0 - #131
Conversation
… api of lua creation
|
is there any reason this hasn't recieved any attention |
|
should def be merged. |
this version is non-trivial to move to, take this abstraction as an example: /** @type {?WASMoon.LuaEngine|WASMoon_5_1.Lua} */
let Lua = null;
// Note: WASMoon 1.x
if( "LuaFactory" in Instance.Backend )
{
const Factory = new Instance.Backend.LuaFactory( ModuleURL, Env );
/**
* @param {string} File
* @param {string | ArrayBufferView} Contents
*/
Instance.MountFile = ( File, Contents ) =>
{
Factory.mountFileSync( /** @type {WASMoon.LuaWasm} */( Instance.WASM ), File, Contents );
}
Lua = await Factory.createEngine( { openStandardLibs: false, traceAllocations: true } );
}
else if( "Lua" in Instance.Backend )
{
// Note: WASMoon 2.x
if( "load" in Instance.Backend.Lua )
{
console.error( "WASMoon v2 isn't released yet!" );
/*
const Factory = await Instance.Backend.Lua.load(
{
wasmFile: ModuleURL,
env: Env
} );
/**
* @param {string} File
* @param {string | ArrayBufferView} Contents
*\/
Instance.MountFile = ( File, Contents ) =>
{
Factory.mountFileSync( /** @type {WASMoon.LuaWasm} *\/( Instance.WASM ), File, Contents );
}
Lua = Factory.createState( { openStandardLibs: false, traceAllocations: true } );
*/
}
// Note: WASMoon Lua 5.1 fork
else if( "create" in Instance.Backend.Lua )
{
/**
* @param {string} File
* @param {string | ArrayBufferView} Contents
*/
Instance.MountFile = function( File, Contents )
{
/** @type {WASMoon_5_1.Lua} */( this.Lua ).mountFile( File, Contents );
}
Lua = await Instance.Backend.Lua.create(
{
customWasmUri: ModuleURL,
environmentVariables: Env,
openStandardLibs: false,
traceAllocations: true
} );
}
}Having a simple version check would highly simplify the above.
While that is true, said function depends on lua already being created so it might be a bit late depending on the situation (ex. for deciding which wasm file to fetch) But I was also talking about things that the following (5.1 compatible) code showcases: // Note: wasmoon currently doesn't expose lua_pushglobaltable(), or LUA_RIDX_GLOBALS, so we use the raw value, which is 2
if( "lua_geti" in this.WASM ) this.WASM.lua_geti( L, this.Backend.LUA_REGISTRYINDEX, 2n );
else if( "LUA_GLOBALSINDEX" in this.Backend ) this.WASM.lua_pushvalue( L, this.Backend.LUA_GLOBALSINDEX );Side-Note: integer based functions like
A lot of the newer functions and features can theoretically be aliased, polyfilled to a degree, or outright ignored. const Value = BigInt( "luaL_len" in this.WASM ? this.WASM.luaL_len( L, -1 ) : "lua_objlen" in this.WASM ? this.WASM.lua_objlen( L, -1 ) : -1 );As an side note: |
I don't think it's the best solution, although I adopted it and it worked well; Lua's ABI has few and at the same time fragile changes. @ceifa What if we could perhaps resolve dynamic symbols? Something like checking if there's a |
Co-authored-by: Artur Koshtei <gh.public10110@gmail.com>
LUA_USE_JUMPTABLE=0 makes luaV_execute dispatch through a switch instead of computed gotos. Wasm has no indirect branch, so clang lowers every computed goto back into a switch anyway, only with the dispatch duplicated at each opcode: the plain switch is ~4 KB smaller and measured no slower (heapsort ran ~20% faster) with emsdk 6.0.9.
Fixes #21 #83 #127 #149 #148 #143 #134
Tried to fix #61, but emscripten have a very limited support for deno