/script_binding/lua/lua_ftk_callbacks.c

http://ftk.googlecode.com/ · C · 177 lines · 140 code · 37 blank · 0 comment · 0 complexity · f84fc69c2f1c09ca2be38b62688b6976 MD5 · raw file

  1. #include <ftk.h>
  2. #include "lua.h"
  3. #include "lualib.h"
  4. #include "lauxlib.h"
  5. #include "tolua++.h"
  6. static lua_State* s_current_L = NULL;
  7. void lua_callbacks_init(lua_State* L)
  8. {
  9. s_current_L = L;
  10. return;
  11. }
  12. Ret lua_ftk_prepare_options_menu_func(void* ctx, FtkWidget* menu_panel)
  13. {
  14. Ret ret = RET_OK;
  15. const char* func = ctx;
  16. lua_State *L = s_current_L;
  17. lua_getglobal(L, func);
  18. tolua_pushusertype(L, menu_panel, "FtkWidget");
  19. lua_call(L, 1, 1);
  20. ret = (int)lua_tonumber(L, -1);
  21. lua_pop(L, 1);
  22. return ret;
  23. }
  24. Ret lua_ftk_on_event_func(void* ctx, FtkEvent* event)
  25. {
  26. printf("%s:%d\n", __func__, __LINE__);
  27. return RET_OK;
  28. }
  29. Ret lau_ftk_widget_on_event_func(FtkWidget* thiz, FtkEvent* event)
  30. {
  31. printf("%s:%d\n", __func__, __LINE__);
  32. return RET_OK;
  33. }
  34. void lua_ftk_destroy_func(void* ctx)
  35. {
  36. printf("%s:%d\n", __func__, __LINE__);
  37. return;
  38. }
  39. Ret lua_ftk_idle_func(void* ctx)
  40. {
  41. Ret ret = RET_OK;
  42. const char* func = ctx;
  43. lua_State *L = s_current_L;
  44. lua_getglobal(L, func);
  45. lua_call(L, 0, 1);
  46. ret = (int)lua_tonumber(L, -1);
  47. lua_pop(L, 1);
  48. printf("%s:%d\n", __func__, __LINE__);
  49. return ret;
  50. }
  51. Ret lua_ftk_timer_func(void* ctx)
  52. {
  53. Ret ret = RET_OK;
  54. const char* func = ctx;
  55. lua_State *L = s_current_L;
  56. lua_getglobal(L, func);
  57. lua_call(L, 0, 1);
  58. ret = (int)lua_tonumber(L, -1);
  59. lua_pop(L, 1);
  60. printf("%s:%d ret=%d\n", __func__, __LINE__, ret);
  61. return ret;
  62. }
  63. int lua_ftk_compare_func(const void* obj1, const void* obj2)
  64. {
  65. printf("%s:%d\n", __func__, __LINE__);
  66. return 0;
  67. }
  68. Ret lua_ftk_listener_func(void* ctx, void* obj)
  69. {
  70. Ret ret = RET_OK;
  71. const char* func = ctx;
  72. lua_State *L = s_current_L;
  73. lua_getglobal(L, func);
  74. lua_pushlightuserdata(L, obj);
  75. lua_call(L, 1, 1);
  76. ret = (int)lua_tonumber(L, -1);
  77. lua_pop(L, 1);
  78. return ret;
  79. }
  80. Ret lua_ftk_file_browser_on_choosed_func(void* ctx, int index, const char* path)
  81. {
  82. Ret ret = RET_OK;
  83. const char* func = ctx;
  84. lua_State *L = s_current_L;
  85. lua_getglobal(L, func);
  86. lua_pushinteger(L, index);
  87. lua_pushstring(L, path);
  88. lua_call(L, 2, 1);
  89. ret = (int)lua_tonumber(L, -1);
  90. lua_pop(L, 1);
  91. return ret;
  92. }
  93. Ret lua_ftk_list_item_listener_func(void* ctx, void* obj)
  94. {
  95. Ret ret = RET_OK;
  96. const char* func = ctx;
  97. lua_State *L = s_current_L;
  98. lua_getglobal(L, func);
  99. tolua_pushusertype(L, obj, "FtkListItemInfo");
  100. lua_call(L, 1, 1);
  101. ret = (int)lua_tonumber(L, -1);
  102. lua_pop(L, 1);
  103. return ret;
  104. }
  105. Ret lua_ftk_widget_listener_func(void* ctx, void* obj)
  106. {
  107. Ret ret = RET_OK;
  108. const char* func = ctx;
  109. lua_State *L = s_current_L;
  110. lua_getglobal(L, func);
  111. tolua_pushusertype(L, obj, "FtkWidget");
  112. lua_call(L, 1, 1);
  113. ret = (int)lua_tonumber(L, -1);
  114. lua_pop(L, 1);
  115. return ret;
  116. }
  117. Ret lua_ftk_event_listener_func(void* ctx, void* obj)
  118. {
  119. Ret ret = RET_OK;
  120. const char* func = ctx;
  121. lua_State *L = s_current_L;
  122. lua_getglobal(L, func);
  123. tolua_pushusertype(L, obj, "FtkEvent");
  124. lua_call(L, 1, 1);
  125. ret = (int)lua_tonumber(L, -1);
  126. lua_pop(L, 1);
  127. return ret;
  128. }
  129. Ret lua_ftk_icon_view_item_listener_func(void* ctx, void* obj)
  130. {
  131. Ret ret = RET_OK;
  132. const char* func = ctx;
  133. lua_State *L = s_current_L;
  134. lua_getglobal(L, func);
  135. tolua_pushusertype(L, obj, "FtkIconViewItem");
  136. lua_call(L, 1, 1);
  137. ret = (int)lua_tonumber(L, -1);
  138. lua_pop(L, 1);
  139. return ret;
  140. }