initial code for lua plugin.
authorPeng Wu <epico@dhcp-65-116.nay.redhat.com>
Tue, 9 Mar 2010 10:38:14 +0000 (18:38 +0800)
committerPeng Wu <alexepico@gmail.com>
Wed, 19 May 2010 02:09:31 +0000 (10:09 +0800)
lua/lua-plugin-init.c [new file with mode: 0644]

diff --git a/lua/lua-plugin-init.c b/lua/lua-plugin-init.c
new file mode 100644 (file)
index 0000000..4dcd5a6
--- /dev/null
@@ -0,0 +1,53 @@
+#include <stdio.h>
+#include <glib.h>
+
+#include "lua.h"
+#include "lualib.h"
+#include "lauxlib.h"
+
+/* the Lua interpreter */
+static lua_State * L = NULL;
+
+static int lua_plugin_init(){
+  /* initialize Lua */
+  L = lua_open();
+  
+  /* enable libs in sandbox */
+  luaopen_base(L);
+  luaopen_io(L);
+  luaopen_string(L);
+  luaopen_math(L);
+  luaopen_table(L);
+  
+  
+}
+
+static const luaL_Reg imelib[] = {
+  {"get_last_commit", ime_get_last_commit},
+  {"get_version", ime_get_version},
+#if 0
+  {"join_string"}, ime_join_string},
+  {"parse_mapping", ime_parse_mapping},
+  {"register_command", ime_register_command},
+  /* Note: the register_trigger function is dropped for ibus-pinyin. */
+  {"register_trigger", ime_register_trigger},
+  {"split_string", ime_split_string},
+  {"trim_string_left", ime_trim_string_left},
+  {"trim_string_right", ime_trim_string_right},
+  {"trim_string", ime_trim_string},
+#endif
+  {NULL, NULL}
+};
+
+static int ime_get_last_commit(lua_State* L){
+  /*TODO: not implemented. */
+  g_assert_not_reached();
+  lua_pushstring(L, "");
+  return 1;
+}
+
+static int ime_get_version(lua_State* L){
+  /* TODO: replace this with C macros. */
+  lua_pushstring(L, "ibus-pinyin 1.2.99");
+  return 1;
+}