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[] = { /*functions defined above (refs can be called by lua)*/ {"start_lua", start}, {"stop_lua", stop}, {"test_lua", test}, {NULL, NULL}, }; exampleplugin::init(); /*L, class name to call in lua, dispatcher, constructor, destructor, functions*/ g_createClass(L, "Exampleplugin", "EventDispatcher", NULL, NULL, functionlist); Exampleplugin *p = new Exampleplugin(); g_pushInstance(L, "Exampleplugin", p->object()); lua_setglobal(L,"exampleplugin"); lua_getglobal(L, "Event"); lua_pushstring(L, EXAMPLEPLUGIN_STATE); lua_setfield(L, -2, "EXAMPLEPLUGIN_STATE"); lua_pushstring(L, EXAMPLEPLUGIN_WIFI); lua_setfield(L, -2, "EXAMPLEPLUGIN_WIFI"); lua_pop(L, 1); return 0; }
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 init(lua_State* L) { const char *iabp = luaL_checkstring(L, 1); IAB *iab = new IAB(L, iabp); g_pushInstance(L, "IAB", iab->object()); luaL_rawgetptr(L, LUA_REGISTRYINDEX, &keyWeak); lua_pushvalue(L, -2); luaL_rawsetptr(L, -2, iab); lua_pop(L, 1); lua_pushvalue(L, -1); 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[] = { {"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; }
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; }