PageRenderTime 52ms CodeModel.GetById 23ms app.highlight 22ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  7static lua_State* s_current_L = NULL;
  8
  9void lua_callbacks_init(lua_State* L)
 10{
 11	s_current_L = L;
 12
 13	return;
 14}
 15
 16Ret lua_ftk_prepare_options_menu_func(void* ctx, FtkWidget* menu_panel)
 17{
 18    Ret ret = RET_OK;
 19    const char* func = ctx;
 20    lua_State *L = s_current_L;
 21
 22    lua_getglobal(L, func);
 23	tolua_pushusertype(L, menu_panel, "FtkWidget");
 24    lua_call(L, 1, 1);
 25    ret = (int)lua_tonumber(L, -1);
 26    lua_pop(L, 1);
 27
 28    return ret;
 29}
 30
 31Ret lua_ftk_on_event_func(void* ctx, FtkEvent* event)
 32{
 33	printf("%s:%d\n", __func__, __LINE__);
 34
 35	return RET_OK;
 36}
 37
 38Ret  lau_ftk_widget_on_event_func(FtkWidget* thiz, FtkEvent* event)
 39{
 40	printf("%s:%d\n", __func__, __LINE__);
 41
 42	return RET_OK;
 43}
 44
 45void lua_ftk_destroy_func(void* ctx)
 46{
 47	printf("%s:%d\n", __func__, __LINE__);
 48
 49	return;
 50}
 51
 52Ret lua_ftk_idle_func(void* ctx)
 53{
 54    Ret ret = RET_OK;
 55    const char* func = ctx;
 56    lua_State *L = s_current_L;
 57
 58    lua_getglobal(L, func);
 59    lua_call(L, 0, 1);
 60    ret = (int)lua_tonumber(L, -1);
 61    lua_pop(L, 1);
 62
 63	printf("%s:%d\n", __func__, __LINE__);
 64    return ret;
 65}
 66
 67Ret lua_ftk_timer_func(void* ctx)
 68{
 69    Ret ret = RET_OK;
 70    const char* func = ctx;
 71    lua_State *L = s_current_L;
 72
 73    lua_getglobal(L, func);
 74    lua_call(L, 0, 1);
 75    ret = (int)lua_tonumber(L, -1);
 76    lua_pop(L, 1);
 77
 78	printf("%s:%d ret=%d\n", __func__, __LINE__, ret);
 79    return ret;
 80}
 81
 82int lua_ftk_compare_func(const void* obj1, const void* obj2)
 83{
 84	printf("%s:%d\n", __func__, __LINE__);
 85	return 0;
 86}
 87
 88Ret lua_ftk_listener_func(void* ctx, void* obj)
 89{
 90    Ret ret = RET_OK;
 91    const char* func = ctx;
 92    lua_State *L = s_current_L;
 93
 94    lua_getglobal(L, func);
 95    lua_pushlightuserdata(L, obj);
 96    lua_call(L, 1, 1);
 97    ret = (int)lua_tonumber(L, -1);
 98    lua_pop(L, 1);
 99
100    return ret;
101}
102
103Ret lua_ftk_file_browser_on_choosed_func(void* ctx, int index, const char* path)
104{
105    Ret ret = RET_OK;
106    const char* func = ctx;
107    lua_State *L = s_current_L;
108
109    lua_getglobal(L, func);
110    lua_pushinteger(L, index);
111	lua_pushstring(L, path);
112    lua_call(L, 2, 1);
113    ret = (int)lua_tonumber(L, -1);
114    lua_pop(L, 1);
115
116    return ret;
117}
118
119Ret lua_ftk_list_item_listener_func(void* ctx, void* obj)
120{
121    Ret ret = RET_OK;
122    const char* func = ctx;
123    lua_State *L = s_current_L;
124
125    lua_getglobal(L, func);
126	tolua_pushusertype(L, obj, "FtkListItemInfo");
127    lua_call(L, 1, 1);
128    ret = (int)lua_tonumber(L, -1);
129    lua_pop(L, 1);
130
131    return ret;
132}
133
134Ret lua_ftk_widget_listener_func(void* ctx, void* obj)
135{
136    Ret ret = RET_OK;
137    const char* func = ctx;
138    lua_State *L = s_current_L;
139
140    lua_getglobal(L, func);
141	tolua_pushusertype(L, obj, "FtkWidget");
142    lua_call(L, 1, 1);
143    ret = (int)lua_tonumber(L, -1);
144    lua_pop(L, 1);
145
146    return ret;
147}
148
149Ret lua_ftk_event_listener_func(void* ctx, void* obj)
150{
151    Ret ret = RET_OK;
152    const char* func = ctx;
153    lua_State *L = s_current_L;
154
155    lua_getglobal(L, func);
156	tolua_pushusertype(L, obj, "FtkEvent");
157    lua_call(L, 1, 1);
158    ret = (int)lua_tonumber(L, -1);
159    lua_pop(L, 1);
160
161    return ret;
162}
163
164Ret lua_ftk_icon_view_item_listener_func(void* ctx, void* obj)
165{
166    Ret ret = RET_OK;
167    const char* func = ctx;
168    lua_State *L = s_current_L;
169
170    lua_getglobal(L, func);
171	tolua_pushusertype(L, obj, "FtkIconViewItem");
172    lua_call(L, 1, 1);
173    ret = (int)lua_tonumber(L, -1);
174    lua_pop(L, 1);
175
176    return ret;
177}