]> khamidou — GitHub mirrors - vice.git/commitdiff
added func to get cursor position
authorkarim hamidou <khamidou@gmail.com>
Tue, 8 Jul 2014 16:28:28 +0000 (18:28 +0200)
committerkarim hamidou <khamidou@gmail.com>
Tue, 8 Jul 2014 16:28:28 +0000 (18:28 +0200)
main.lua
vice.c

index 93f6bff8681c4d0e7052ea83c5f019f4a17d2f32..cc3011406afad39c261dcbbdc07dff74f0d3745e 100644 (file)
--- a/main.lua
+++ b/main.lua
@@ -1,4 +1,4 @@
 function keyboard_event_handler (keycode)
-    display("Kaaris Kaaris")
+    display(get_cursor_position())
     io.write("Hello world, from ",keycode,"!\n")
 end
diff --git a/vice.c b/vice.c
index 6205f8191165357c4eace37ab0008e5b75699715..0a2189012ac27510f3fca921a92043cdfb505669 100644 (file)
--- a/vice.c
+++ b/vice.c
@@ -36,6 +36,13 @@ static int minibuffer_write(lua_State *L) {
     return 0; 
 }
 
+static int get_cursor_position(lua_State *L) {
+    int len = 0;
+    len = SSM(SCI_GETCURRENTPOS, 0, 0);
+    lua_pushnumber(L, len);
+    return 1;
+}
+
 static gboolean handle_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data) {
     lua_pushstring(vice_lua_state, "keyboard_event_handler");
     lua_gettable(vice_lua_state, LUA_GLOBALSINDEX);               /* function to be called */
@@ -72,7 +79,6 @@ int main(int argc, char **argv) {
     SSM(SCI_STYLESETFORE, SCE_C_WORD, 0x800000);
     SSM(SCI_STYLESETFORE, SCE_C_STRING, 0x800080);
     SSM(SCI_STYLESETBOLD, SCE_C_OPERATOR, 1);
-    int len = 0;
 
     vice_lua_state = lua_open();
 
@@ -84,6 +90,7 @@ int main(int argc, char **argv) {
     luaopen_loadlib(vice_lua_state);
     
     lua_register(vice_lua_state, "display", minibuffer_write);
+    lua_register(vice_lua_state, "get_cursor_position", get_cursor_position);
 
     int s = luaL_loadfile(vice_lua_state, "main.lua");
 
@@ -92,8 +99,7 @@ int main(int argc, char **argv) {
       s = lua_pcall(vice_lua_state, 0, LUA_MULTRET, 0);
     }
 
-    SSM(SCI_GETLENGTH, len, 0);
-    printf("length: %d\n", len);
+    SSM(SCI_INSERTTEXT, 0, (sptr_t) "YOLO SWAG");
 
     gtk_widget_show_all(app);
     gtk_widget_grab_focus(GTK_WIDGET(editor));