ime register command in progress.
authorPeng Wu <epico@dhcp-65-116.nay.redhat.com>
Tue, 13 Apr 2010 07:55:07 +0000 (15:55 +0800)
committerPeng Wu <alexepico@gmail.com>
Wed, 19 May 2010 02:09:32 +0000 (10:09 +0800)
lua/lua-plugin-init.c
lua/lua-plugin.c
lua/lua-plugin.h
lua/test-lua-plugin.c

index 42c6f5c..996b314 100644 (file)
@@ -29,6 +29,25 @@ void lua_plugin_openlibs (lua_State *L) {
   }
 }
 
+void lua_plugin_store_plugin(lua_State * L, IBusEnginePlugin * plugin){
+  luaL_newmetatable(L, LUA_IMELIBNAME);
+  lua_pushliteral(L, LUA_IMELIB_CONTEXT);
+  lua_pushlightuserdata(L, plugin);
+  lua_rawset(L, -3);
+  lua_pop(L, 1);
+}
+
+IBusEnginePlugin * lua_plugin_retrieve_plugin(lua_State * L) {
+  luaL_newmetatable(L, LUA_IMELIBNAME);
+  lua_pushliteral(L, LUA_IMELIB_CONTEXT);
+  lua_rawget(L, -2);
+  luaL_checktype(L, -1, LUA_TLIGHTUSERDATA);
+  IBusEnginePlugin * plugin = lua_touserdata(L, -1);
+  g_assert(IBUS_IS_ENGINE_PLUGIN(plugin));
+  lua_pop(L, 2);
+  return plugin;
+}
+
 static int ime_get_last_commit(lua_State* L){
   /*TODO: not implemented. */
   fprintf(stderr, "TODO: ime_get_last_commit unimplemented.\n");
index 7eb99d6..ac03e15 100644 (file)
@@ -83,6 +83,8 @@ ibus_engine_plugin_init (IBusEnginePlugin *self)
   memset(priv, 0, sizeof(IBusEnginePluginPrivate));
 
   lua_plugin_init(priv);
+
+  lua_plugin_store_plugin(priv->L, self);
 }
 
 IBusEnginePlugin * ibus_engine_plugin_new(){
index 2d50329..084fe15 100644 (file)
@@ -5,8 +5,7 @@
 
 #define LUA_IMELIBNAME   "ime"
 LUALIB_API int (luaopen_ime) (lua_State * L);
-
-void lua_plugin_openlibs (lua_State *L);
+#define LUA_IMELIB_CONTEXT "__context"
 
 typedef struct{
   const char * command_name;
@@ -31,6 +30,10 @@ typedef struct _IBusEnginePlugin IBusEnginePlugin;
 typedef struct _IBusEnginePluginClass IBusEnginePluginClass;
 typedef struct _IBusEnginePluginPrivate IBusEnginePluginPrivate;
 
+void lua_plugin_openlibs (lua_State *L);
+void lua_plugin_store_plugin(lua_State * L, IBusEnginePlugin * plugin);
+IBusEnginePlugin * lua_plugin_retrieve_plugin(lua_State * L);
+
 struct _IBusEnginePlugin
 {
   GObject parent_instance;
index 44e5586..72ec552 100644 (file)
@@ -44,6 +44,8 @@ int main(int argc, char * argv[]){
   lua_State * L = ibus_engine_plugin_get_lua_State(plugin);
   run_test(L, "test.lua");
   
+  g_assert(lua_plugin_retrieve_plugin(L) == plugin);
+
   g_object_unref(plugin);
 
   return 0;