/* ** Open io library */ void iolib_open (void) { in=stdin; out=stdout; lua_register ("readfrom", io_readfrom); lua_register ("writeto", io_writeto); lua_register ("appendto", io_appendto); lua_register ("read", io_read); lua_register ("readuntil",io_readuntil); lua_register ("write", io_write); lua_register ("execute", io_execute); lua_register ("remove", io_remove); lua_register ("getenv", io_getenv); lua_register ("time", io_time); lua_register ("date", io_date); lua_register ("beep", io_beep); lua_register ("exit", io_exit); lua_register ("debug", io_debug); lua_register ("print_stack", errorfb); lua_setfallback("error", errorfb); }
void LuaBase::registerLua() { // Register system table lua_Object system_table = lua_createtable(); lua_pushobject(system_table); lua_setglobal("system"); lua_pushobject(system_table); refSystemTable = lua_ref(1); for (unsigned i = 0; i < ARRAYSIZE(system_defaults); i++) { lua_pushobject(lua_getref(refSystemTable)); lua_pushstring(system_defaults[i].name); lua_pushnumber(system_defaults[i].key); lua_settable(); } // Create and populate system.controls table lua_Object controls_table = lua_createtable(); lua_pushobject(lua_getref(refSystemTable)); lua_pushstring("controls"); lua_pushobject(controls_table); lua_settable(); for (int i = 0; controls[i].name; i++) { lua_pushobject(controls_table); lua_pushstring(controls[i].name); lua_pushnumber(controls[i].key); lua_settable(); } lua_pushobject(lua_getref(refSystemTable)); lua_pushstring("camChangeHandler"); lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler)); lua_settable(); lua_pushobject(lua_getref(refSystemTable)); lua_pushstring("axisHandler"); lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler)); lua_settable(); lua_pushobject(lua_getref(refSystemTable)); lua_pushstring("buttonHandler"); lua_pushcfunction(LUA_OPCODE(LuaBase, dummyHandler)); lua_settable(); lua_pushobject(lua_getglobal("type")); refTypeOverride = lua_ref(true); lua_pushCclosure(LUA_OPCODE(LuaBase, typeOverride), 0); lua_setglobal("type"); // Register constants for box types lua_pushnumber(Sector::NoneType); lua_setglobal("NONE"); lua_pushnumber(Sector::WalkType); lua_setglobal("WALK"); lua_pushnumber(Sector::CameraType); lua_setglobal("CAMERA"); lua_pushnumber(Sector::SpecialType); lua_setglobal("SPECIAL"); lua_pushnumber(Sector::HotType); lua_setglobal("HOT"); lua_pushobject(lua_setfallback("concat", LUA_OPCODE(LuaBase, concatFallback))); refOldConcatFallback = lua_ref(1); // initialize Text globals lua_pushstring("x"); refTextObjectX = lua_ref(true); lua_pushstring("y"); refTextObjectY = lua_ref(true); lua_pushstring("font"); refTextObjectFont = lua_ref(true); lua_pushstring("width"); refTextObjectWidth = lua_ref(true); lua_pushstring("height"); refTextObjectHeight = lua_ref(true); lua_pushstring("fgcolor"); refTextObjectFGColor = lua_ref(true); lua_pushstring("bgcolor"); refTextObjectBGColor = lua_ref(true); lua_pushstring("fxcolor"); refTextObjectFXColor = lua_ref(true); lua_pushstring("hicolor"); refTextObjectHIColor = lua_ref(true); lua_pushstring("duration"); refTextObjectDuration = lua_ref(true); lua_pushstring("center"); refTextObjectCenter = lua_ref(true); lua_pushstring("ljustify"); refTextObjectLJustify = lua_ref(true); lua_pushstring("rjustify"); refTextObjectRJustify = lua_ref(true); lua_pushstring("volume"); refTextObjectVolume = lua_ref(true); lua_pushstring("pan"); refTextObjectPan = lua_ref(true); lua_pushstring("background"); refTextObjectBackground = lua_ref(true); }
/* ** Open math library */ void mathlib_open (void) { luaI_openlib(mathlib, (sizeof(mathlib)/sizeof(mathlib[0]))); old_pow = lua_refobject(lua_setfallback("arith", math_pow), 1); }