Logo loophole letters

Running LUA on the Web

code

Let’s try to run lua in the browser! I’ve found wasmoon to be a viable solution (next fo fengari).

It’s quite easy to get a Lua evaluator running:

const factory = new LuaFactory();
const lua = await factory.createEngine();
const code = `
function multiply(x, y)
  return x * y
end
function main()
  print("Hello!")
  return multiply(10, 11)
end
`;
await lua.doString(code);
const main = lua.global.get("main");
const result = main();
console.log(result);

Let’s drop this into a component to be able to live code with lua:

ms

You can also run the code with ctrl+enter!

Fibonacci comparison

Let’s compare the runtimes of Lua and JS, using fibonacci:

ms

In JavaScript:

ms

It looks like Lua is significantly slower than JS. I know this is not a full benchmark, blabla.

That’s already it, I might do some more Lua stuff in the future. Bye

❤️ 2024 Felix Roos | mastodon | github