LuaState constructor

LuaState({
  1. bool openlibs = true,
})

Creates a new lua_State and wraps it.

If openlibs is false then standard libraries such as math, string, table, etc will no longer be available as globals.

Implementation

LuaState({bool openlibs = true}) : L = luaL_newstate() {
  if (openlibs) luaL_openlibs(L);
  lua_atnativeerror(L, allowInterop((_) {
    // Log fatal errors to JS console, Fengari has poor internal
    // error management (catchall everywhere) so it isn't possible
    // to recover a lot of exceptions during calls themselves. :/

    (context["console"] as JsObject)
      .callMethod("error", [lua_touserdata(L, -1)]);
  }));
}