GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - recogni/lua-wasm: Recogni's fork of lua wasm building toolkit for AstroLab

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

51 Commits
51 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
scripts
scripts
 
 
src
src
 
 
.eslintignore
.eslintignore
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.json
.prettierrc.json
 
 
README.md
README.md
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
simple-test.ts
simple-test.ts
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

Lua WASM Bindings

WASM bindings and binaries for 5.4.6

Building

  • Install emscripten using your native package manager (eg pacman, apt, brew, etc ...)
    • https://emscripten.org/index.html
  • Run ./scripts/setup.sh
  • Run npm run build (or whatever JS build system you use)

Important

The binding script doesn't include the entire Lua API, some effort might be needed to add missing features. For the complete Lua API reference, visit https://www.lua.org/manual/5.4/manual.html

Example

import { LUA_OK } from "lua-wasm-bindings/dist/lua";

import { lauxlib, lua, lualib } from "lua-wasm-bindings/dist/lua.54";

const luaCode = `return "Hello"`;
consol.log(executeLua(luaCode));

function executeLua(luaCode: string): string | Error | never {
  const L = lauxlib.luaL_newstate();
  lualib.luaL_openlibs(L);

  // Optional Load modules
  // lua.lua_getglobal(L, "package");
  // lua.lua_getfield(L, -1, "preload");
  // lauxlib.luaL_loadstring(L, jsonLib); // Load extenal package from string
  // lua.lua_setfield(L, -2, "json");

  const status = lauxlib.luaL_dostring(L, luaCode);

  if (status === LUA_OK) {
    if (lua.lua_isstring(L, -1)) {
      const result = lua.lua_tostring(L, -1);
      lua.lua_close(L);
      return result === null ? undefined : result;
    } else {
      const returnType = lua.lua_typename(L, lua.lua_type(L, -1));
      lua.lua_close(L);
      throw new Error(`Unsupported Lua return type: ${returnType}`);
    }
  } else {
    const luaStackString = lua.lua_tostring(L, -1);
    const message = luaStackString.replace(/^\[string "(--)?\.\.\."\]:\d+: /, "");
    lua.lua_close(L);
    return new Error(message);
  }
}

About

Recogni's fork of lua wasm building toolkit for AstroLab

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.