GeolocationBinder::GeolocationBinder(lua_State *L) { Binder binder(L); static const luaL_Reg functionList[] = { {"isAvailable", isAvailable}, {"isHeadingAvailable", isHeadingAvailable}, {"setAccuracy", setAccuracy}, {"getAccuracy", getAccuracy}, {"setThreshold", setThreshold}, {"getThreshold", getThreshold}, {"start", start}, {"stop", stop}, {"startUpdatingLocation", startUpdatingLocation}, {"stopUpdatingLocation", stopUpdatingLocation}, {"startUpdatingHeading", startUpdatingHeading}, {"stopUpdatingHeading", stopUpdatingHeading}, {NULL, NULL}, }; binder.createClass("Geolocation", "EventDispatcher", create, destruct, functionList); lua_getglobal(L, "Event"); lua_pushstring(L, LOCATION_UPDATE.type()); lua_setfield(L, -2, "LOCATION_UPDATE"); lua_pushstring(L, HEADING_UPDATE.type()); lua_setfield(L, -2, "HEADING_UPDATE"); lua_pop(L, 1); luaL_newweaktable(L); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key); }
static int loader(lua_State *L) { const luaL_Reg functionlist[] = { {"isConsole", isConsole}, {"getStore", getStore}, {NULL, NULL}, }; g_createClass(L, "StoreDetector", NULL, NULL, destruct, functionlist); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); StoreDetector *sd = new StoreDetector(L); g_pushInstance(L, "StoreDetector", sd->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, sd); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "storedetector"); return 1; }
static int loader(lua_State *L) { const luaL_Reg functionList[] = { {"loadBanner", loadBanner}, {"removeBanner", removeBanner}, {"showBanner", showBanner}, {"hideBanner", hideBanner}, {"getAlignment", getAlignment}, {"setAlignment", setAlignment}, {"getAutoRefresh", getAutoRefresh}, {"loadInterstitial", loadInterstitial}, {"showInterstitial", showInterstitial}, {NULL, NULL} }; g_createClass(L, "MoPub", "EventDispatcher", NULL, destruct, functionList); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "MoPub"); lua_pushstring(L, "top"); lua_setfield(L, -2, "ALIGN_TOP"); lua_pushstring(L, "bottom"); lua_setfield(L, -2, "ALIGN_BOTTOM"); lua_pop(L, 1); lua_getglobal(L, "Event"); lua_pushstring(L, AD_WILL_LOAD); lua_setfield(L, -2, "AD_WILL_LOAD"); lua_pushstring(L, AD_LOADED); lua_setfield(L, -2, "AD_LOADED"); lua_pushstring(L, AD_FAILED); lua_setfield(L, -2, "AD_FAILED"); lua_pushstring(L, AD_CLOSED); lua_setfield(L, -2, "AD_CLOSED"); lua_pushstring(L, INTERSTITIAL_LOADED); lua_setfield(L, -2, "INTERSTITIAL_LOADED"); lua_pushstring(L, INTERSTITIAL_FAILED); lua_setfield(L, -2, "INTERSTITIAL_FAILED"); lua_pushstring(L, INTERSTITIAL_CLOSED); lua_setfield(L, -2, "INTERSTITIAL_CLOSED"); lua_pop(L, 1); MoPub *mopub = new MoPub(L); g_pushInstance(L, "MoPub", mopub->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, mopub); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "mopub"); return 1; }
static int loader(lua_State *L) { const luaL_Reg functionList[] = { {"configure", configure}, {"showBanner", showBanner}, {"hideBanner", hideBanner}, {"showInterstitial", showInterstitial}, {NULL, NULL} }; g_createClass(L, "Greystripe", "EventDispatcher", NULL, destruct, functionList); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "Greystripe"); lua_pushstring(L, "top"); lua_setfield(L, -2, "ALIGN_TOP"); lua_pushstring(L, "bottom"); lua_setfield(L, -2, "ALIGN_BOTTOM"); lua_pop(L, 1); lua_getglobal(L, "Event"); lua_pushstring(L, BANNER_LOADED); lua_setfield(L, -2, "BANNER_LOADED"); lua_pushstring(L, BANNER_FAILED); lua_setfield(L, -2, "BANNER_FAILED"); lua_pushstring(L, BANNER_CLOSED); lua_setfield(L, -2, "BANNER_CLOSED"); lua_pushstring(L, BANNER_CLICKED); lua_setfield(L, -2, "BANNER_CLICKED"); lua_pushstring(L, INTERSTITIAL_LOADED); lua_setfield(L, -2, "INTERSTITIAL_LOADED"); lua_pushstring(L, INTERSTITIAL_FAILED); lua_setfield(L, -2, "INTERSTITIAL_FAILED"); lua_pushstring(L, INTERSTITIAL_CLOSED); lua_setfield(L, -2, "INTERSTITIAL_CLOSED"); lua_pushstring(L, INTERSTITIAL_CLICKED); lua_setfield(L, -2, "INTERSTITIAL_CLICKED"); lua_pop(L, 1); Greystripe *greystripe = new Greystripe(L); g_pushInstance(L, "Greystripe", greystripe->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, greystripe); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "greystripe"); return 1; }
static int loader(lua_State *L) { const luaL_Reg functionlist[] = { {"purchaseItem", purchaseItem}, {NULL, NULL}, }; g_createClass(L, "SamsungIAP", "EventDispatcher", NULL, destruct, functionlist); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "SamsungIAP"); lua_pushstring(L, OK); lua_setfield(L, -2, "OK"); lua_pushstring(L, ERROR); lua_setfield(L, -2, "ERROR"); lua_pushstring(L, PURCHASED); lua_setfield(L, -2, "PURCHASED"); lua_pushstring(L, CANCELED); lua_setfield(L, -2, "CANCELED"); lua_pushstring(L, INAPP); lua_setfield(L, -2, "INAPP"); lua_pushstring(L, SUBS); lua_setfield(L, -2, "SUBS"); lua_pop(L, 1); lua_getglobal(L, "Event"); lua_pushstring(L, PURCHASE_STATE_CHANGE); lua_setfield(L, -2, "PURCHASE_STATE_CHANGE"); lua_pop(L, 1); SamsungIAP *samsungiap = new SamsungIAP(L); g_pushInstance(L, "SamsungIAP", samsungiap->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, samsungiap); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "samsungiap"); return 1; }
static int loader(lua_State *L) { const luaL_Reg functionlist[] = { {"detectStores", detectStores}, {"new", init}, {"setUp", setup}, {"setProducts", setProducts}, {"setConsumables", setConsumables}, {"isAvailable", check}, {"requestProducts", request}, {"purchase", purchase}, {"restore", restore}, {NULL, NULL}, }; g_createClass(L, "IAB", "EventDispatcher", NULL, destruct, functionlist); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "Event"); lua_pushstring(L, AVAILABLE); lua_setfield(L, -2, "AVAILABLE"); lua_pushstring(L, NOT_AVAILABLE); lua_setfield(L, -2, "NOT_AVAILABLE"); lua_pushstring(L, PURCHASE_COMPLETE); lua_setfield(L, -2, "PURCHASE_COMPLETE"); lua_pushstring(L, PURCHASE_ERROR); lua_setfield(L, -2, "PURCHASE_ERROR"); lua_pushstring(L, PRODUCTS_COMPLETE); lua_setfield(L, -2, "PRODUCTS_COMPLETE"); lua_pushstring(L, PRODUCTS_ERROR); lua_setfield(L, -2, "PRODUCTS_ERROR"); lua_pushstring(L, RESTORE_COMPLETE); lua_setfield(L, -2, "RESTORE_COMPLETE"); lua_pushstring(L, RESTORE_ERROR); lua_setfield(L, -2, "RESTORE_ERROR"); lua_pop(L, 1); return 0; }
int loader(lua_State *L) { ::L = L; lua_pushlightuserdata(L, &keyClasses); lua_newtable(L); lua_settable(L, LUA_REGISTRYINDEX); lua_pushlightuserdata(L, &keyObject); lua_newtable(L); lua_pushcfunction(L, __index); lua_setfield(L, -2, "__index"); lua_settable(L, LUA_REGISTRYINDEX); lua_pushlightuserdata(L, &keyObjects); luaL_newweaktable(L, "v"); lua_settable(L, LUA_REGISTRYINDEX); lua_pushlightuserdata(L, &keyMetatableWithGC); lua_newtable(L); lua_pushcfunction(L, __gc); lua_setfield(L, -2, "__gc"); lua_settable(L, LUA_REGISTRYINDEX); lua_newtable(L); lua_pushcfunction(L, getClass); lua_setfield(L, -2, "getClass"); lua_pushcfunction(L, createClass); lua_setfield(L, -2, "createClass"); lua_pushvalue(L, -1); lua_setglobal(L, "native"); return 1; }
static int bindAll(lua_State* L) { Application* application = static_cast<Application*>(lua_touserdata(L, 1)); lua_pop(L, 1); StackChecker checker(L, "bindAll", 0); setEnvironTable(L); { lua_newtable(L); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_touches); lua_newtable(L); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_eventClosures); lua_newtable(L); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_events); luaL_newweaktable(L); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_b2); lua_newtable(L); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_timers); } luaL_newmetatable(L, "Object"); lua_setglobal(L, "Object"); EventBinder eventBinder(L); EventDispatcherBinder eventDispatcherBinder(L); TimerBinder timerBinder(L); MatrixBinder matrixBinder(L); SpriteBinder spriteBinder(L); TextureBaseBinder textureBaseBinder(L); TextureBinder textureBinder(L); TexturePackBinder texturePackBinder(L); BitmapDataBinder bitmapDataBinder(L); BitmapBinder bitmapBinder(L); StageBinder stageBinder(L, application); FontBaseBinder fontBaseBinder(L); FontBinder fontBinder(L); TTFontBinder ttfontBinder(L); TextFieldBinder textFieldBinder(L); AccelerometerBinder accelerometerBinder(L); Box2DBinder2 box2DBinder2(L); DibBinder dibBinder(L); TileMapBinder tileMapBinder(L); ApplicationBinder applicationBinder(L); ShapeBinder shapeBinder(L); MovieClipBinder movieClipBinder(L); UrlLoaderBinder urlLoaderBinder(L); GeolocationBinder geolocationBinder(L); GyroscopeBinder gyroscopeBinder(L); AlertDialogBinder alertDialogBinder(L); TextInputDialogBinder textInputDialogBinder(L); MeshBinder meshBinder(L); AudioBinder audioBinder(L); RenderTargetBinder renderTargetBinder(L); PluginManager& pluginManager = PluginManager::instance(); for (size_t i = 0; i < pluginManager.plugins.size(); ++i) pluginManager.plugins[i].main(L, 0); lua_getglobal(L, "Event"); lua_getfield(L, -1, "new"); lua_pushlightuserdata(L, NULL); lua_call(L, 1, 1); lua_remove(L, -2); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_Event); lua_getglobal(L, "Event"); lua_getfield(L, -1, "new"); lua_pushlightuserdata(L, NULL); lua_call(L, 1, 1); lua_remove(L, -2); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_EnterFrameEvent); lua_getglobal(L, "Event"); lua_getfield(L, -1, "new"); lua_pushlightuserdata(L, NULL); lua_call(L, 1, 1); lua_remove(L, -2); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_MouseEvent); lua_getglobal(L, "Event"); lua_getfield(L, -1, "new"); lua_pushlightuserdata(L, NULL); lua_call(L, 1, 1); lua_remove(L, -2); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_TouchEvent); lua_getglobal(L, "Event"); lua_getfield(L, -1, "new"); lua_pushlightuserdata(L, NULL); lua_call(L, 1, 1); lua_remove(L, -2); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_TimerEvent); lua_getglobal(L, "Event"); lua_getfield(L, -1, "new"); lua_pushlightuserdata(L, NULL); lua_call(L, 1, 1); lua_remove(L, -2); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_KeyboardEvent); lua_getglobal(L, "Event"); lua_getfield(L, -1, "new"); lua_pushlightuserdata(L, NULL); lua_call(L, 1, 1); lua_remove(L, -2); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &key_CompleteEvent); #include "property.c.in" #include "texturepack.c.in" #include "sprite.c.in" #include "compatibility.c.in" lua_newtable(L); lua_pushinteger(L, GINPUT_KEY_BACK); lua_setfield(L, -2, "BACK"); lua_pushinteger(L, GINPUT_KEY_SEARCH); lua_setfield(L, -2, "SEARCH"); lua_pushinteger(L, GINPUT_KEY_MENU); lua_setfield(L, -2, "MENU"); lua_pushinteger(L, GINPUT_KEY_CENTER); lua_setfield(L, -2, "CENTER"); lua_pushinteger(L, GINPUT_KEY_SELECT); lua_setfield(L, -2, "SELECT"); lua_pushinteger(L, GINPUT_KEY_START); lua_setfield(L, -2, "START"); lua_pushinteger(L, GINPUT_KEY_L1); lua_setfield(L, -2, "L1"); lua_pushinteger(L, GINPUT_KEY_R1); lua_setfield(L, -2, "R1"); lua_pushinteger(L, GINPUT_KEY_LEFT); lua_setfield(L, -2, "LEFT"); lua_pushinteger(L, GINPUT_KEY_UP); lua_setfield(L, -2, "UP"); lua_pushinteger(L, GINPUT_KEY_RIGHT); lua_setfield(L, -2, "RIGHT"); lua_pushinteger(L, GINPUT_KEY_DOWN); lua_setfield(L, -2, "DOWN"); lua_pushinteger(L, GINPUT_KEY_A); lua_setfield(L, -2, "A"); lua_pushinteger(L, GINPUT_KEY_B); lua_setfield(L, -2, "B"); lua_pushinteger(L, GINPUT_KEY_C); lua_setfield(L, -2, "C"); lua_pushinteger(L, GINPUT_KEY_D); lua_setfield(L, -2, "D"); lua_pushinteger(L, GINPUT_KEY_E); lua_setfield(L, -2, "E"); lua_pushinteger(L, GINPUT_KEY_F); lua_setfield(L, -2, "F"); lua_pushinteger(L, GINPUT_KEY_G); lua_setfield(L, -2, "G"); lua_pushinteger(L, GINPUT_KEY_H); lua_setfield(L, -2, "H"); lua_pushinteger(L, GINPUT_KEY_I); lua_setfield(L, -2, "I"); lua_pushinteger(L, GINPUT_KEY_J); lua_setfield(L, -2, "J"); lua_pushinteger(L, GINPUT_KEY_K); lua_setfield(L, -2, "K"); lua_pushinteger(L, GINPUT_KEY_L); lua_setfield(L, -2, "L"); lua_pushinteger(L, GINPUT_KEY_M); lua_setfield(L, -2, "M"); lua_pushinteger(L, GINPUT_KEY_N); lua_setfield(L, -2, "N"); lua_pushinteger(L, GINPUT_KEY_O); lua_setfield(L, -2, "O"); lua_pushinteger(L, GINPUT_KEY_P); lua_setfield(L, -2, "P"); lua_pushinteger(L, GINPUT_KEY_Q); lua_setfield(L, -2, "Q"); lua_pushinteger(L, GINPUT_KEY_R); lua_setfield(L, -2, "R"); lua_pushinteger(L, GINPUT_KEY_S); lua_setfield(L, -2, "S"); lua_pushinteger(L, GINPUT_KEY_T); lua_setfield(L, -2, "T"); lua_pushinteger(L, GINPUT_KEY_U); lua_setfield(L, -2, "U"); lua_pushinteger(L, GINPUT_KEY_V); lua_setfield(L, -2, "V"); lua_pushinteger(L, GINPUT_KEY_W); lua_setfield(L, -2, "W"); lua_pushinteger(L, GINPUT_KEY_X); lua_setfield(L, -2, "X"); lua_pushinteger(L, GINPUT_KEY_Y); lua_setfield(L, -2, "Y"); lua_pushinteger(L, GINPUT_KEY_Z); lua_setfield(L, -2, "Z"); lua_pushinteger(L, GINPUT_KEY_0); lua_setfield(L, -2, "NUM_0"); lua_pushinteger(L, GINPUT_KEY_1); lua_setfield(L, -2, "NUM_1"); lua_pushinteger(L, GINPUT_KEY_2); lua_setfield(L, -2, "NUM_2"); lua_pushinteger(L, GINPUT_KEY_3); lua_setfield(L, -2, "NUM_3"); lua_pushinteger(L, GINPUT_KEY_4); lua_setfield(L, -2, "NUM_4"); lua_pushinteger(L, GINPUT_KEY_5); lua_setfield(L, -2, "NUM_5"); lua_pushinteger(L, GINPUT_KEY_6); lua_setfield(L, -2, "NUM_6"); lua_pushinteger(L, GINPUT_KEY_7); lua_setfield(L, -2, "NUM_7"); lua_pushinteger(L, GINPUT_KEY_8); lua_setfield(L, -2, "NUM_8"); lua_pushinteger(L, GINPUT_KEY_9); lua_setfield(L, -2, "NUM_9"); lua_setglobal(L, "KeyCode"); // correct clock function which is wrong in iphone lua_getglobal(L, "os"); lua_pushcfunction(L, os_timer); lua_setfield(L, -2, "timer"); lua_pop(L, 1); // register collectgarbagelater // lua_pushcfunction(L, ::collectgarbagelater); // lua_setglobal(L, "collectgarbagelater"); registerModules(L); return 0; }
static int loader(lua_State *L) { const luaL_Reg functionlist[] = { {"isAvailable", isAvailable}, {"login", login}, {"logout", logout}, {"showLeaderboard", showLeaderboard}, {"reportScore", reportScore}, {"showAchievements", showAchievements}, {"reportAchievement", reportAchievement}, {"loadAchievements", loadAchievements}, {"loadScores", loadScores}, {"loadPlayerScores", loadPlayerScores}, {"getCurrentPlayer", getCurrentPlayer}, {"getCurrentPlayerId", getCurrentPlayerId}, {"loadState", loadState}, {"updateState", updateState}, {"resolveState", resolveState}, {"deleteState", deleteState}, {NULL, NULL}, }; g_createClass(L, "GooglePlay", "EventDispatcher", NULL, destruct, functionlist); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "Event"); lua_pushstring(L, LOGIN_ERROR); lua_setfield(L, -2, "LOGIN_ERROR"); lua_pushstring(L, LOGIN_COMPLETE); lua_setfield(L, -2, "LOGIN_COMPLETE"); lua_pushstring(L, LOAD_SCORES_COMPLETE); lua_setfield(L, -2, "LOAD_SCORES_COMPLETE"); lua_pushstring(L, REPORT_SCORE_COMPLETE); lua_setfield(L, -2, "REPORT_SCORE_COMPLETE"); lua_pushstring(L, LOAD_ACHIEVEMENTS_COMPLETE); lua_setfield(L, -2, "LOAD_ACHIEVEMENTS_COMPLETE"); lua_pushstring(L, REPORT_ACHIEVEMENT_COMPLETE); lua_setfield(L, -2, "REPORT_ACHIEVEMENT_COMPLETE"); lua_pushstring(L, STATE_LOADED); lua_setfield(L, -2, "STATE_LOADED"); lua_pushstring(L, STATE_ERROR); lua_setfield(L, -2, "STATE_ERROR"); lua_pushstring(L, STATE_CONFLICT); lua_setfield(L, -2, "STATE_CONFLICT"); lua_pushstring(L, STATE_DELETED); lua_setfield(L, -2, "STATE_DELETED"); lua_pop(L, 1); lua_getglobal(L, "GooglePlay"); lua_pushstring(L, TODAY); lua_setfield(L, -2, "TODAY"); lua_pushstring(L, WEEK); lua_setfield(L, -2, "WEEK"); lua_pushstring(L, ALL_TIME); lua_setfield(L, -2, "ALL_TIME"); lua_pushstring(L, FRIENDS); lua_setfield(L, -2, "FRIENDS"); lua_pushstring(L, ALL_PLAYERS); lua_setfield(L, -2, "ALL_PLAYERS"); lua_pushnumber(L, UNLOCKED); lua_setfield(L, -2, "UNLOCKED"); lua_pushnumber(L, REVEALED); lua_setfield(L, -2, "REVEALED"); lua_pushnumber(L, HIDDEN); lua_setfield(L, -2, "HIDDEN"); lua_pop(L, 1); GooglePlay *gms = new GooglePlay(L); g_pushInstance(L, "GooglePlay", gms->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, gms); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "googleplay"); return 1; }
int EventDispatcherBinder::addEventListener(lua_State* L) { StackChecker checker(L, "EventDispatcherBinder::addEventListener", 0); Binder binder(L); EventDispatcher* eventDispatcher = static_cast<EventDispatcher*>(binder.getInstance("EventDispatcher", 1)); luaL_checktype(L, 2, LUA_TSTRING); luaL_checktype(L, 3, LUA_TFUNCTION); bool hasData = !lua_isnoneornil(L, 4); createEventsTable(L, 1); // create self.__events table if it's not created EventBinderMap& map = getOrCreateEventBinderMap(eventDispatcher); const char* event = lua_tostring(L, 2); int eventid = StringId::instance().id(event); const std::vector<CppLuaBridge*>& bridges = map[eventid]; lua_getfield(L, 1, "__events"); // key is CppLuaBridge*, value is 'event check closure' // check if the event is already registered bool isFound = false; for (std::size_t i = 0; i < bridges.size(); ++i) { lua_pushlightuserdata(L, bridges[i]); lua_rawget(L, -2); // we get the event check closure if (hasData == false) { lua_pushvalue(L, 3); // function lua_call(L, 1, 1); } else { lua_pushvalue(L, 3); // function lua_pushvalue(L, 4); // data lua_call(L, 2, 1); } if (lua_toboolean(L, -1)) { lua_pop(L, 1); isFound = true; break; } else lua_pop(L, 1); } if (isFound == true) { lua_pop(L, 1); // pop __events, leave stack as it is return 0; } LuaApplication *application = (LuaApplication*)luaL_getdata(L); lua_State *mainL = application->getLuaState(); CppLuaBridge* bridge = new CppLuaBridge(mainL); // create event closure luaL_rawgetptr(L, LUA_REGISTRYINDEX, &key_eventClosures); lua_pushlightuserdata(L, bridge); // key=bridge if (hasData == false) // value=closure { // self ve function'in eventClosure'in icine upvalue olarak koyulmasi garbage collect edilmesini engelliyor // bu yuzden {self, function} seklinde bi weak table yaratip ilk upvalue olarak onu set ediyoruz luaL_newweaktable(L); lua_pushvalue(L, 1); // self lua_rawseti(L, -2, 1); lua_pushvalue(L, 3); // function lua_rawseti(L, -2, 2); lua_pushcclosure(L, &eventClosure, 1); } else { // self, function ve data'nin eventClosure'in icine upvalue olarak koyulmasi garbage collect edilmesini engelliyor // bu yuzden {self, function, data} seklinde bi weak table yaratip ilk upvalue olarak onu set ediyoruz luaL_newweaktable(L); lua_pushvalue(L, 1); // self lua_rawseti(L, -2, 1); lua_pushvalue(L, 3); // function lua_rawseti(L, -2, 2); lua_pushvalue(L, 4); // data lua_rawseti(L, -2, 3); lua_pushcclosure(L, &eventClosureWithData, 1); } lua_rawset(L, -3); // envtable["eventClosures"][bridge] = closure lua_pop(L, 1); // pop envtable["eventClosures"] // create event check closure lua_pushlightuserdata(L, bridge); if (hasData == false) { lua_pushvalue(L, 3); // function lua_pushcclosure(L, &eventCheckClosure, 1); } else { lua_pushvalue(L, 3); // function lua_pushvalue(L, 4); // data lua_pushcclosure(L, &eventCheckClosureWithData, 2); } lua_rawset(L, -3); map.push_back(eventid, bridge); bridge->unref(); eventDispatcher->addEventListener(LuaEvent::Type(event), bridge, &CppLuaBridge::luaEvent); lua_pop(L, 1); // pop __events, leave stack as it is return 0; }
static int loader(lua_State *L) { const luaL_Reg functionlist[] = { {"isAnyAvailable", isAnyAvailable}, {"getPlayerCount", getPlayerCount}, {"getControllerName", getControllerName}, {"getPlayers", getPlayers}, {"vibrate", vibrate}, {"setDeadZone", lSetDeadZone}, {NULL, NULL}, }; g_createClass(L, "Controller", "EventDispatcher", NULL, destruct, functionlist); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "Event"); lua_pushstring(L, RIGHT_JOYSTICK); lua_setfield(L, -2, "RIGHT_JOYSTICK"); lua_pushstring(L, LEFT_JOYSTICK); lua_setfield(L, -2, "LEFT_JOYSTICK"); lua_pushstring(L, RIGHT_TRIGGER); lua_setfield(L, -2, "RIGHT_TRIGGER"); lua_pushstring(L, LEFT_TRIGGER); lua_setfield(L, -2, "LEFT_TRIGGER"); lua_pushstring(L, AXIS_JOYSTICK); lua_setfield(L, -2, "AXIS_JOYSTICK"); lua_pushstring(L, CONNECTED); lua_setfield(L, -2, "CONNECTED"); lua_pushstring(L, DISCONNECTED); lua_setfield(L, -2, "DISCONNECTED"); lua_pop(L, 1); lua_getglobal(L, "KeyCode"); lua_pushnumber(L, DPAD_DOWN); lua_setfield(L, -2, "DPAD_DOWN"); lua_pushnumber(L, DPAD_LEFT); lua_setfield(L, -2, "DPAD_LEFT"); lua_pushnumber(L, DPAD_RIGHT); lua_setfield(L, -2, "DPAD_RIGHT"); lua_pushnumber(L, DPAD_UP); lua_setfield(L, -2, "DPAD_UP"); lua_pushnumber(L, BUTTON_L1); lua_setfield(L, -2, "BUTTON_L1"); lua_pushnumber(L, BUTTON_L2); lua_setfield(L, -2, "BUTTON_L2"); lua_pushnumber(L, BUTTON_L3); lua_setfield(L, -2, "BUTTON_L3"); lua_pushnumber(L, BUTTON_R1); lua_setfield(L, -2, "BUTTON_R1"); lua_pushnumber(L, BUTTON_R2); lua_setfield(L, -2, "BUTTON_R2"); lua_pushnumber(L, BUTTON_R3); lua_setfield(L, -2, "BUTTON_R3"); lua_pushnumber(L, BUTTON_MENU); lua_setfield(L, -2, "BUTTON_MENU"); lua_pushnumber(L, BUTTON_BACK); lua_setfield(L, -2, "BUTTON_BACK"); lua_pushnumber(L, BUTTON_A); lua_setfield(L, -2, "BUTTON_A"); lua_pushnumber(L, BUTTON_X); lua_setfield(L, -2, "BUTTON_X"); lua_pushnumber(L, BUTTON_Y); lua_setfield(L, -2, "BUTTON_Y"); lua_pushnumber(L, BUTTON_B); lua_setfield(L, -2, "BUTTON_B"); lua_pop(L, 1); Controller *c = new Controller(L); g_pushInstance(L, "Controller", c->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, c); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "controller"); return 1; }
static int loader(lua_State *L) { const luaL_Reg functionlist[] = { {"login", login}, {"logout", logout}, {"getAccessToken", getAccessToken}, {"getExpirationDate", getExpirationDate}, {"dialog", dialog}, {"get", request}, {"post", post}, {"delete", deleteRequest}, {"getProfile", getProfile}, {"getFriends", getFriends}, {"getAlbums", getAlbums}, {"getAppRequests", getAppRequests}, {"getScores", getScores}, {"postScore", postScore}, {"postPhoto", postPhoto}, {"postToFeed", postToFeed}, {"inviteFriends", inviteFriends}, {"share", share}, {"upload", upload}, {NULL, NULL}, }; g_createClass(L, "Facebook", "EventDispatcher", NULL, destruct, functionlist); // create a weak table in LUA_REGISTRYINDEX that can be accessed with the address of keyWeak luaL_newweaktable(L, "v"); luaL_rawsetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_getglobal(L, "Event"); lua_pushstring(L, LOGIN_COMPLETE); lua_setfield(L, -2, "LOGIN_COMPLETE"); lua_pushstring(L, LOGIN_ERROR); lua_setfield(L, -2, "LOGIN_ERROR"); lua_pushstring(L, LOGOUT_COMPLETE); lua_setfield(L, -2, "LOGOUT_COMPLETE"); lua_pushstring(L, LOGOUT_ERROR); lua_setfield(L, -2, "LOGOUT_ERROR"); lua_pushstring(L, OPEN_URL); lua_setfield(L, -2, "OPEN_URL"); lua_pushstring(L, DIALOG_COMPLETE); lua_setfield(L, -2, "DIALOG_COMPLETE"); lua_pushstring(L, DIALOG_ERROR); lua_setfield(L, -2, "DIALOG_ERROR"); lua_pushstring(L, REQUEST_COMPLETE); lua_setfield(L, -2, "REQUEST_COMPLETE"); lua_pushstring(L, REQUEST_ERROR); lua_setfield(L, -2, "REQUEST_ERROR"); lua_pop(L, 1); GFacebook *facebook = new GFacebook; g_pushInstance(L, "Facebook", facebook->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, facebook); lua_pop(L, 1); lua_pushvalue(L, -1); lua_setglobal(L, "facebook"); return 1; }