load method

void load(
  1. List<int> data
)

Loads code from a buffer whether it be Lua or compiled bytecode and pushes the resulting lua function to the stack.

If code fails to parse or compile, a LuaException is thrown.

Implementation

void load(List<int> data) {
  var t = top;
  int code;
  if ((code = luaL_loadstring(L, toUint8Array(data))) != 0) {
    // Sometimes Fengari will return an invalid error code and not push an
    // error string but still call our lua_atnativeerror, at the moment these
    // types of errors are not properly propagated using the LuaException but
    // are logged in console.
    var e = "Unknown load error $code";
    if (lua_gettop(L) > t) { // Error string was pushed
      e = popString();
    } // Else error wasn't pushed, Fengari bug.
    throw LuaException(e);
  }
}