Skip to content

Commit

Permalink
chore(widget): replace normal widget methods with rotable
Browse files Browse the repository at this point in the history
Signed-off-by: Xu Xingliang <[email protected]>
  • Loading branch information
XuNeo committed Jul 21, 2024
1 parent d1b2e33 commit b8bb4b9
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 112 deletions.
17 changes: 9 additions & 8 deletions src/anim.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "luavgl.h"
#include "private.h"
#include "rotable.h"

/**
* Different to lvgl anim, anim in lua can be restarted after it's done.
Expand Down Expand Up @@ -319,15 +320,15 @@ static const luaL_Reg luavgl_anim_meta[] = {
{NULL, NULL },
};

static const luaL_Reg luavgl_anim_methods[] = {
{"set", luavgl_anim_set },
{"start", luavgl_anim_start },
static const rotable_Reg luavgl_anim_methods[] = {
{"set", LUA_TFUNCTION, {luavgl_anim_set} },
{"start", LUA_TFUNCTION, {luavgl_anim_start} },

/* in lua anim, stopped anim can be restarted. */
{"stop", luavgl_anim_stop },
{"delete", luavgl_anim_delete},
/* in lua anim, stopped anim can be restarted. */
{"stop", LUA_TFUNCTION, {luavgl_anim_stop} },
{"delete", LUA_TFUNCTION, {luavgl_anim_delete}},

{NULL, NULL }
{0, 0, {0} }
};

static void luavgl_anim_init(lua_State *L)
Expand All @@ -336,7 +337,7 @@ static void luavgl_anim_init(lua_State *L)
luaL_newmetatable(L, "lv_anim");
luaL_setfuncs(L, luavgl_anim_meta, 0);

luaL_newlib(L, luavgl_anim_methods);
rotable_newlib(L, luavgl_anim_methods);
lua_setfield(L, -2, "__index");

lua_pop(L, 1); /* pop metatable */
Expand Down
42 changes: 21 additions & 21 deletions src/disp.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "luavgl.h"
#include "private.h"
#include "rotable.h"

typedef struct luavgl_disp_s {
lv_disp_t *disp;
Expand Down Expand Up @@ -255,30 +256,29 @@ static int luavgl_disp_set_rotation(lua_State *L)
/**
* luavgl.disp lib
*/
static const luaL_Reg disp_lib[] = {
{"get_default", luavgl_disp_get_default },
{"get_scr_act", luavgl_disp_get_scr_act },
{"get_scr_prev", luavgl_disp_get_scr_prev},
{"get_next", luavgl_disp_get_next },
{"load_scr", luavgl_disp_load_scr },

{NULL, NULL },
static const rotable_Reg disp_lib[] = {
{"get_default", LUA_TFUNCTION, {luavgl_disp_get_default} },
{"get_scr_act", LUA_TFUNCTION, {luavgl_disp_get_scr_act} },
{"get_scr_prev", LUA_TFUNCTION, {luavgl_disp_get_scr_prev}},
{"get_next", LUA_TFUNCTION, {luavgl_disp_get_next} },
{"load_scr", LUA_TFUNCTION, {luavgl_disp_load_scr} },

{0, 0, {0} },
};

/*
** methods for disp handles
*/
static const luaL_Reg disp_methods[] = {
{"get_layer_top", luavgl_disp_get_layer_top},
{"get_layer_sys", luavgl_disp_get_layer_sys},
{"get_next", luavgl_disp_get_next },
{"set_rotation", luavgl_disp_set_rotation },
{"get_res", luavgl_disp_get_res },

{"get_scr_act", luavgl_disp_get_scr_act },
{"get_scr_prev", luavgl_disp_get_scr_prev },

{NULL, NULL },
static const rotable_Reg disp_methods[] = {
{"get_layer_top", LUA_TFUNCTION, {luavgl_disp_get_layer_top}},
{"get_layer_sys", LUA_TFUNCTION, {luavgl_disp_get_layer_sys}},
{"get_next", LUA_TFUNCTION, {luavgl_disp_get_next} },
{"set_rotation", LUA_TFUNCTION, {luavgl_disp_set_rotation} },
{"get_res", LUA_TFUNCTION, {luavgl_disp_get_res} },
{"get_scr_act", LUA_TFUNCTION, {luavgl_disp_get_scr_act} },
{"get_scr_prev", LUA_TFUNCTION, {luavgl_disp_get_scr_prev} },

{0, 0, {0} },
};

static const luaL_Reg disp_meta[] = {
Expand All @@ -293,12 +293,12 @@ static void luavgl_disp_init(lua_State *L)
luaL_newmetatable(L, "lv_disp");
luaL_setfuncs(L, disp_meta, 0);

luaL_newlib(L, disp_methods);
rotable_newlib(L, disp_methods);
lua_setfield(L, -2, "__index");

lua_pop(L, 1); /* pop metatable */

/* luavgl.disp lib */
luaL_newlib(L, disp_lib);
rotable_newlib(L, disp_lib);
lua_setfield(L, -2, "disp");
}
35 changes: 18 additions & 17 deletions src/fs.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "luavgl.h"
#include "private.h"
#include "rotable.h"

typedef struct luavgl_fs_s {
lv_fs_file_t file;
Expand Down Expand Up @@ -310,23 +311,23 @@ static int luavgl_dir_gc(lua_State *L)
* luavgl.fs lib
*
*/
static const luaL_Reg fs_lib[] = {
{"open_file", luavgl_fs_open },
{"open_dir", luavgl_dir_open},
static const rotable_Reg fs_lib[] = {
{"open_file", LUA_TFUNCTION, {luavgl_fs_open} },
{"open_dir", LUA_TFUNCTION, {luavgl_dir_open}},

{NULL, NULL },
{0, 0, {0} },
};

/*
** methods for file handles
*/
static const luaL_Reg fs_methods[] = {
{"read", luavgl_fs_read },
{"write", luavgl_fs_write},
{"close", luavgl_fs_close},
{"seek", luavgl_fs_seek },
static const rotable_Reg fs_methods[] = {
{"read", LUA_TFUNCTION, {luavgl_fs_read} },
{"write", LUA_TFUNCTION, {luavgl_fs_write}},
{"close", LUA_TFUNCTION, {luavgl_fs_close}},
{"seek", LUA_TFUNCTION, {luavgl_fs_seek} },

{NULL, NULL },
{0, 0, {0} },
};

static const luaL_Reg fs_meta[] = {
Expand All @@ -341,11 +342,11 @@ static const luaL_Reg fs_meta[] = {
/*
** methods for dir handles
*/
static const luaL_Reg dir_methods[] = {
{"read", luavgl_dir_read },
{"close", luavgl_dir_close},
static const rotable_Reg dir_methods[] = {
{"read", LUA_TFUNCTION, {luavgl_dir_read} },
{"close", LUA_TFUNCTION, {luavgl_dir_close}},

{NULL, NULL },
{0, 0, {0} },
};

static const luaL_Reg dir_meta[] = {
Expand All @@ -363,7 +364,7 @@ static void luavgl_fs_init(lua_State *L)
luaL_newmetatable(L, "lv_fs");
luaL_setfuncs(L, fs_meta, 0);

luaL_newlib(L, fs_methods);
rotable_newlib(L, fs_methods);
lua_setfield(L, -2, "__index");

lua_pop(L, 1); /* pop metatable */
Expand All @@ -372,12 +373,12 @@ static void luavgl_fs_init(lua_State *L)
luaL_newmetatable(L, "lv_dir");
luaL_setfuncs(L, dir_meta, 0);

luaL_newlib(L, dir_methods);
rotable_newlib(L, dir_methods);
lua_setfield(L, -2, "__index");

lua_pop(L, 1); /* pop metatable */

/* luavgl.fs lib */
luaL_newlib(L, fs_lib);
rotable_newlib(L, fs_lib);
lua_setfield(L, -2, "fs");
}
61 changes: 31 additions & 30 deletions src/group.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "luavgl.h"
#include "private.h"
#include "rotable.h"

typedef struct luavgl_group_s {
lv_group_t *group;
Expand Down Expand Up @@ -288,39 +289,39 @@ static int luavgl_group_gc(lua_State *L)
/**
* luavgl.group lib
*/
static const luaL_Reg group_lib[] = {
{"create", luavgl_group_create },
{"get_default", luavgl_group_get_default},
{"remove_obj", luavgl_group_remove_obj },
{"remove_objs", luavgl_group_remove_objs},

{"focus_obj", luavgl_group_focus_obj },
{NULL, NULL },
static const rotable_Reg group_lib[] = {
{"create", LUA_TFUNCTION, {luavgl_group_create} },
{"get_default", LUA_TFUNCTION, {luavgl_group_get_default}},
{"remove_obj", LUA_TFUNCTION, {luavgl_group_remove_obj} },
{"remove_objs", LUA_TFUNCTION, {luavgl_group_remove_objs}},

{"focus_obj", LUA_TFUNCTION, {luavgl_group_focus_obj} },
{0, 0, {0} },
};

/*
** methods for file handles
*/
static const luaL_Reg group_methods[] = {
{"delete", luavgl_group_delete },
{"set_default", luavgl_group_set_default },
{"add_obj", luavgl_group_add_obj },
{"remove_obj", luavgl_group_remove_obj },
{"focus_next", luavgl_group_focus_next },
{"focus_prev", luavgl_group_focus_prev },
{"focus_freeze", luavgl_group_focus_freeze },
{"send_data", luavgl_group_send_data },
{"set_focus_cb", luavgl_group_set_focus_cb },
{"set_edge_cb", luavgl_group_set_edge_cb },
{"get_focus_cb", luavgl_group_get_focus_cb },
{"get_edge_cb", luavgl_group_get_edge_cb },
{"set_editing", luavgl_group_set_editing },
{"set_wrap", luavgl_group_set_wrap },
{"get_wrap", luavgl_group_get_wrap },
{"get_obj_count", luavgl_group_get_obj_count},
{"get_focused", luavgl_group_get_focused },

{NULL, NULL },
static const rotable_Reg group_methods[] = {
{"delete", LUA_TFUNCTION, {luavgl_group_delete} },
{"set_default", LUA_TFUNCTION, {luavgl_group_set_default} },
{"add_obj", LUA_TFUNCTION, {luavgl_group_add_obj} },
{"remove_obj", LUA_TFUNCTION, {luavgl_group_remove_obj} },
{"focus_next", LUA_TFUNCTION, {luavgl_group_focus_next} },
{"focus_prev", LUA_TFUNCTION, {luavgl_group_focus_prev} },
{"focus_freeze", LUA_TFUNCTION, {luavgl_group_focus_freeze} },
{"send_data", LUA_TFUNCTION, {luavgl_group_send_data} },
{"set_focus_cb", LUA_TFUNCTION, {luavgl_group_set_focus_cb} },
{"set_edge_cb", LUA_TFUNCTION, {luavgl_group_set_edge_cb} },
{"get_focus_cb", LUA_TFUNCTION, {luavgl_group_get_focus_cb} },
{"get_edge_cb", LUA_TFUNCTION, {luavgl_group_get_edge_cb} },
{"set_editing", LUA_TFUNCTION, {luavgl_group_set_editing} },
{"set_wrap", LUA_TFUNCTION, {luavgl_group_set_wrap} },
{"get_wrap", LUA_TFUNCTION, {luavgl_group_get_wrap} },
{"get_obj_count", LUA_TFUNCTION, {luavgl_group_get_obj_count}},
{"get_focused", LUA_TFUNCTION, {luavgl_group_get_focused} },

{0, 0, {0} },
};

static const luaL_Reg group_meta[] = {
Expand All @@ -336,12 +337,12 @@ static void luavgl_group_init(lua_State *L)
luaL_newmetatable(L, "lv_group");
luaL_setfuncs(L, group_meta, 0);

luaL_newlib(L, group_methods);
rotable_newlib(L, group_methods);
lua_setfield(L, -2, "__index");

lua_pop(L, 1); /* pop metatable */

/* luavgl.indev lib */
luaL_newlib(L, group_lib);
rotable_newlib(L, group_lib);
lua_setfield(L, -2, "group");
}
45 changes: 23 additions & 22 deletions src/indev.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "luavgl.h"
#include "private.h"
#include "rotable.h"

typedef struct luavgl_indev_s {
lv_indev_t *indev;
Expand Down Expand Up @@ -294,36 +295,36 @@ static int luavgl_indev_gc(lua_State *L)
/**
* luavgl.indev lib
*/
static const luaL_Reg indev_lib[] = {
{"get_act", luavgl_indev_get_act },
static const rotable_Reg indev_lib[] = {
{"get_act", LUA_TFUNCTION, {luavgl_indev_get_act} },
#if 0
{"get_obj_act", luavgl_indev_get_obj_act},
{"get_obj_act", LUA_TFUNCTION, {luavgl_indev_get_obj_act}},
#endif
{"get_next", luavgl_indev_get_next },
{"get_next", LUA_TFUNCTION, {luavgl_indev_get_next}},

{NULL, NULL },
{0, 0, {0} },
};

/*
** methods for file handles
*/
static const luaL_Reg methods[] = {
{"get_type", luavgl_indev_get_type },
{"reset", luavgl_indev_reset },
{"reset_long_press", luavgl_indev_reset_long_press},
{"set_cursor", luavgl_indev_set_cursor },
{"set_group", luavgl_indev_set_group },
{"get_point", luavgl_indev_get_point },
{"get_gesture_dir", luavgl_indev_get_gesture_dir },
{"get_key", luavgl_indev_get_key },
{"get_scroll_dir", luavgl_indev_get_scroll_dir },
{"get_scroll_obj", luavgl_indev_get_scroll_obj },
{"get_vect", luavgl_indev_get_vect },
{"wait_release", luavgl_indev_wait_release },
static const rotable_Reg methods[] = {
{"get_type", LUA_TFUNCTION, {luavgl_indev_get_type} },
{"reset", LUA_TFUNCTION, {luavgl_indev_reset} },
{"reset_long_press", LUA_TFUNCTION, {luavgl_indev_reset_long_press}},
{"set_cursor", LUA_TFUNCTION, {luavgl_indev_set_cursor} },
{"set_group", LUA_TFUNCTION, {luavgl_indev_set_group} },
{"get_point", LUA_TFUNCTION, {luavgl_indev_get_point} },
{"get_gesture_dir", LUA_TFUNCTION, {luavgl_indev_get_gesture_dir} },
{"get_key", LUA_TFUNCTION, {luavgl_indev_get_key} },
{"get_scroll_dir", LUA_TFUNCTION, {luavgl_indev_get_scroll_dir} },
{"get_scroll_obj", LUA_TFUNCTION, {luavgl_indev_get_scroll_obj} },
{"get_vect", LUA_TFUNCTION, {luavgl_indev_get_vect} },
{"wait_release", LUA_TFUNCTION, {luavgl_indev_wait_release} },
#if 0
{"on_event", luavgl_indev_on_event },
{"on_event", LUA_TFUNCTION, {luavgl_indev_on_event} },
#endif
{NULL, NULL },
{0, 0, {0} },
};

static const luaL_Reg meta[] = {
Expand All @@ -340,12 +341,12 @@ static void luavgl_indev_init(lua_State *L)
luaL_newmetatable(L, "lv_indev");
luaL_setfuncs(L, meta, 0);

luaL_newlib(L, methods);
rotable_newlib(L, methods);
lua_setfield(L, -2, "__index");

lua_pop(L, 1); /* pop metatable */

/* luavgl.indev lib */
luaL_newlib(L, indev_lib);
rotable_newlib(L, indev_lib);
lua_setfield(L, -2, "indev");
}
13 changes: 7 additions & 6 deletions src/style.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "luavgl.h"
#include "private.h"
#include "rotable.h"

typedef struct {
lv_style_t style;
Expand Down Expand Up @@ -727,12 +728,12 @@ static int luavgl_obj_remove_style_all(lua_State *L)
return 0;
}

static const luaL_Reg luavgl_style_methods[] = {
{"set", luavgl_style_set },
{"delete", luavgl_style_delete },
{"remove_prop", luavgl_style_remove_prop},
static const rotable_Reg luavgl_style_methods[] = {
{"set", LUA_TFUNCTION, {luavgl_style_set} },
{"delete", LUA_TFUNCTION, {luavgl_style_delete} },
{"remove_prop", LUA_TFUNCTION, {luavgl_style_remove_prop}},

{NULL, NULL }
{0, 0, {0} }
};

static void luavgl_style_init(lua_State *L)
Expand All @@ -742,7 +743,7 @@ static void luavgl_style_init(lua_State *L)
lua_pushcfunction(L, luavgl_style_gc);
lua_setfield(L, -2, "__gc");

luaL_newlib(L, luavgl_style_methods); /* methods belong to this type */
rotable_newlib(L, luavgl_style_methods); /* methods belong to this type */
lua_setfield(L, -2, "__index");

lua_pop(L, 1); /* pop __index table */
Expand Down
Loading

0 comments on commit b8bb4b9

Please sign in to comment.