#include "gideros.h" #include "lauxlib.h" #include "lua.h" #define LUA_LIB #include //this is for debugginh purpose //and should be commented out before deployment //you can log using //__android_log_print(ANDROID_LOG_DEBUG, "tag", "Output String"); //#include //some configurations of our plugin static const char* pluginName = "testPlugin"; static const char* pluginVersion = "1.0"; static const char* javaClassName = "com/giderosmobile/android/Plugin"; //Store Java Environment reference static JNIEnv *ENV; //Store our main class, what we will use as plugin static jclass cls; //example method static int test(lua_State *L) { //__android_log_print(ANDROID_LOG_DEBUG, "testPlugin", "test"); return 1; } //here we register all functions we could call from lua //lua function name as key and C function as value static const struct luaL_Reg funcs[] = { { "test", test }, { NULL, NULL }//don't forget nulls at the end }; //here we register all the C functions for lua //so lua engine would know they exists LUALIB_API int luaopen_plugin(lua_State *L) { luaL_register(L, pluginName, funcs); return 1; } //here we do all our stuff needs to be done on initialization static void g_initializePlugin(lua_State *L) { //get java environment reference ENV = g_getJNIEnv(); //get global package object lua_getglobal(L, "package"); lua_getfield(L, -1, "preload"); //put our plugin name inside with a callback to //registering C functions lua_pushcfunction(L, luaopen_plugin); lua_setfield(L, -2, pluginName); lua_pop(L, 2); } //and here we free everything we need to free static void g_deinitializePlugin(lua_State *L) { } //register our plugin with Gideros lib REGISTER_PLUGIN(pluginName, pluginVersion)