/// <summary> /// Initializes global Lua state. /// </summary> private void InitializeLua() { _gL = Melua.luaL_newstate(); Melua.melua_openlib(_gL, new[] { new Melua.LuaLib("", Melua.meluaopen_basesafe), new Melua.LuaLib("table", Melua.luaopen_table), new Melua.LuaLib("string", Melua.luaopen_string), new Melua.LuaLib("math", Melua.luaopen_math), }); Melua.lua_atpanic(_gL, Melua.CreateFunctionReference(_gL, this.OnPanic)); this.RegisterFunctions(); }
/// <summary> /// Initializes global Lua state. /// </summary> private void InitializeLua() { GL = Melua.luaL_newstate(); Melua.melua_openlib(GL, LuaLib.BaseSafe, LuaLib.Table, LuaLib.String, LuaLib.Math); Melua.lua_atpanic(GL, Melua.CreateFunctionReference(GL, OnPanic)); // Functions // -------------------------------------------------------------- // Setup Register(addnpc); Register(addwarp); // Dialog Register(msg); Register(select); Register(close); Register(input); Register(numinput); Register(openshop); // Information Register(getpc); Register(getnpc); Register(gettime); // Inventory Register(hasitem); Register(countitem); Register(additem); Register(removeitem); // Action Register(warp); Register(resetstats); Register(changehair); Register(spawn); // Others Register(var); Register(logdebug); }
/// <summary> /// Registers function on global Lua state. /// </summary> /// <param name="function"></param> private void Register(Melua.LuaNativeFunction function) { var func = Melua.CreateFunctionReference(GL, function); Melua.lua_register(GL, function.Method.Name, func); }