diff --git a/deps/lvgl b/deps/lvgl index 0e091f6..b8b7e29 160000 --- a/deps/lvgl +++ b/deps/lvgl @@ -1 +1 @@ -Subproject commit 0e091f644d102c82a265a9401d20e064a80c1359 +Subproject commit b8b7e291564985f34bd232acd836154378bff589 diff --git a/examples/test.lua b/examples/test.lua new file mode 100644 index 0000000..581e863 --- /dev/null +++ b/examples/test.lua @@ -0,0 +1,17 @@ +local function Object(t) + local info = debug.getinfo(2, "nS") -- 2 refers to the caller of the function + print("Called from: " .. info.short_src .. ", function " .. (info.name or 'unknown')) + print("table content:") + obj = {table.unpack(t)} + for k, v in pairs(t) do + print(k, v) + end + return obj +end + +Object({ + a = "789", + Object({ + a = "101112", + }) +}) diff --git a/simulator/lv_conf.h b/simulator/lv_conf.h index a8be00c..7280c6b 100644 --- a/simulator/lv_conf.h +++ b/simulator/lv_conf.h @@ -210,7 +210,7 @@ *LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail *LV_LOG_LEVEL_USER Only logs added by the user *LV_LOG_LEVEL_NONE Do not log anything*/ - #define LV_LOG_LEVEL LV_LOG_LEVEL_WARN + #define LV_LOG_LEVEL LV_LOG_LEVEL_INFO /*1: Print the log with 'printf'; *0: User need to register a callback with `lv_log_register_print_cb()`*/ @@ -664,7 +664,9 @@ /* libjpeg-turbo decoder library. * Supports complete JPEG specifications and high-performance JPEG decoding. */ +#ifndef LV_USE_LIBJPEG_TURBO #define LV_USE_LIBJPEG_TURBO 0 +#endif /*GIF decoder library*/ #define LV_USE_GIF 1 diff --git a/simulator/main.c b/simulator/main.c index 24c3f59..083d01c 100644 --- a/simulator/main.c +++ b/simulator/main.c @@ -12,6 +12,7 @@ #include "widgets/widgets.h" #include +#include #if defined(WIN32) || defined(_WIN32) || defined(_WIN32_) || defined(WIN64) || defined(_WIN64) || defined(_WIN64_) #include diff --git a/src/anim.c b/src/anim.c index c0240ba..72cca85 100644 --- a/src/anim.c +++ b/src/anim.c @@ -94,19 +94,19 @@ static void _lv_anim_set_path(void *obj, lua_State *L) } a->path_cb = lv_anim_path_linear; - if (path == NULL || strcmp(path, "linear") == 0) { + if (path == NULL || lv_strcmp(path, "linear") == 0) { ; /* use default linear path */ - } else if (strcmp(path, "ease_in") == 0) { + } else if (lv_strcmp(path, "ease_in") == 0) { a->path_cb = lv_anim_path_ease_in; - } else if (strcmp(path, "ease_out") == 0) { + } else if (lv_strcmp(path, "ease_out") == 0) { a->path_cb = lv_anim_path_ease_out; - } else if (strcmp(path, "ease_in_out") == 0) { + } else if (lv_strcmp(path, "ease_in_out") == 0) { a->path_cb = lv_anim_path_ease_in_out; - } else if (strcmp(path, "overshoot") == 0) { + } else if (lv_strcmp(path, "overshoot") == 0) { a->path_cb = lv_anim_path_overshoot; - } else if (strcmp(path, "bounce") == 0) { + } else if (lv_strcmp(path, "bounce") == 0) { a->path_cb = lv_anim_path_bounce; - } else if (strcmp(path, "step") == 0) { + } else if (lv_strcmp(path, "step") == 0) { a->path_cb = lv_anim_path_step; } } diff --git a/src/disp.c b/src/disp.c index f94f81f..ba68491 100644 --- a/src/disp.c +++ b/src/disp.c @@ -113,38 +113,38 @@ static int luavgl_disp_load_scr(lua_State *L) const char *str; lua_getfield(L, 2, "anim"); str = lua_tostring(L, -1); - if (str == NULL || strcmp(str, "none") == 0) { + if (str == NULL || lv_strcmp(str, "none") == 0) { ; /* use default */ - } else if (strcmp(str, "over_left") == 0) { + } else if (lv_strcmp(str, "over_left") == 0) { anim = LV_SCR_LOAD_ANIM_OVER_LEFT; - } else if (strcmp(str, "over_right") == 0) { + } else if (lv_strcmp(str, "over_right") == 0) { anim = LV_SCR_LOAD_ANIM_OVER_RIGHT; - } else if (strcmp(str, "over_top") == 0) { + } else if (lv_strcmp(str, "over_top") == 0) { anim = LV_SCR_LOAD_ANIM_OVER_TOP; - } else if (strcmp(str, "over_botto") == 0) { + } else if (lv_strcmp(str, "over_botto") == 0) { anim = LV_SCR_LOAD_ANIM_OVER_BOTTOM; - } else if (strcmp(str, "move_left") == 0) { + } else if (lv_strcmp(str, "move_left") == 0) { anim = LV_SCR_LOAD_ANIM_MOVE_LEFT; - } else if (strcmp(str, "move_right") == 0) { + } else if (lv_strcmp(str, "move_right") == 0) { anim = LV_SCR_LOAD_ANIM_MOVE_RIGHT; - } else if (strcmp(str, "move_top") == 0) { + } else if (lv_strcmp(str, "move_top") == 0) { anim = LV_SCR_LOAD_ANIM_MOVE_TOP; - } else if (strcmp(str, "move_botto") == 0) { + } else if (lv_strcmp(str, "move_botto") == 0) { anim = LV_SCR_LOAD_ANIM_MOVE_BOTTOM; - } else if (strcmp(str, "fade_on") == 0) { + } else if (lv_strcmp(str, "fade_on") == 0) { anim = LV_SCR_LOAD_ANIM_FADE_ON; #if LV_VERSION_CHECK(8, 3, 0) - } else if (strcmp(str, "fade_in") == 0) { + } else if (lv_strcmp(str, "fade_in") == 0) { anim = LV_SCR_LOAD_ANIM_FADE_IN; - } else if (strcmp(str, "fade_out") == 0) { + } else if (lv_strcmp(str, "fade_out") == 0) { anim = LV_SCR_LOAD_ANIM_FADE_OUT; - } else if (strcmp(str, "out_left") == 0) { + } else if (lv_strcmp(str, "out_left") == 0) { anim = LV_SCR_LOAD_ANIM_OUT_LEFT; - } else if (strcmp(str, "out_right") == 0) { + } else if (lv_strcmp(str, "out_right") == 0) { anim = LV_SCR_LOAD_ANIM_OUT_RIGHT; - } else if (strcmp(str, "out_top") == 0) { + } else if (lv_strcmp(str, "out_top") == 0) { anim = LV_SCR_LOAD_ANIM_OUT_TOP; - } else if (strcmp(str, "out_bottom") == 0) { + } else if (lv_strcmp(str, "out_bottom") == 0) { anim = LV_SCR_LOAD_ANIM_OUT_BOTTOM; #endif } diff --git a/src/font.c b/src/font.c index 369da39..a3d94e9 100644 --- a/src/font.c +++ b/src/font.c @@ -161,7 +161,7 @@ static int luavgl_get_named_weight(const char *name) } for (int i = 0; i < _ARRAY_LEN(g_named_weight); i++) { - if (strcmp(name, g_named_weight[i].name) == 0) { + if (lv_strcmp(name, g_named_weight[i].name) == 0) { return g_named_weight[i].value; } } @@ -180,7 +180,7 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name, int size, int weight) { /* check builtin font firstly. */ - if (strcmp(name, "montserrat") == 0) { + if (lv_strcmp(name, "montserrat") == 0) { if (FONT_WEIGHT_NORMAL != weight) return NULL; @@ -189,7 +189,7 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name, return g_builtin_montserrat[i].font; } } - } else if (strcmp(name, "unscii") == 0) { + } else if (lv_strcmp(name, "unscii") == 0) { if (FONT_WEIGHT_NORMAL != weight) return NULL; #if LV_FONT_UNSCII_8 @@ -203,14 +203,14 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name, #endif } #if LV_FONT_DEJAVU_16_PERSIAN_HEBREW - else if (strcmp(name, "dejavu_persian_hebrew") == 0) { + else if (lv_strcmp(name, "dejavu_persian_hebrew") == 0) { if (size == 16) return &lv_font_dejavu_16_persian_hebrew; } #endif #if LV_FONT_SIMSUN_16_CJK - else if (strcmp(name, "dejavu_persian_hebrew") == 0) { + else if (lv_strcmp(name, "dejavu_persian_hebrew") == 0) { if (size == 16) return &lv_font_simsun_16_cjk; } @@ -225,6 +225,17 @@ static const lv_font_t *_luavgl_font_create(lua_State *L, const char *name, return NULL; } +static char *luavgl_strchr(const char *s, char c) +{ + while (*s) { + if (c == *s) { + return (char *)s; + } + s++; + } + return NULL; +} + /** * Dynamic font family fallback is not supported. * The fallback only happen when font creation fails and continue to try next @@ -254,7 +265,7 @@ static int luavgl_font_create(lua_State *L) weight = lua_tointeger(L, 3); } else { char *luastr = (char *)lua_tostring(L, 3); - int len = strlen(luastr); + int len = lv_strlen(luastr); if (len > 128) { /* not likely to happen */ return luaL_argerror(L, 3, "too long"); @@ -271,7 +282,7 @@ static int luavgl_font_create(lua_State *L) weight = FONT_WEIGHT_NORMAL; } - str = strdup(lua_tostring(L, 1)); + str = lv_strdup(lua_tostring(L, 1)); if (str == NULL) { return luaL_error(L, "no memory"); } @@ -283,11 +294,11 @@ static int luavgl_font_create(lua_State *L) continue; } - char *end = strchr(name, ','); + char *end = luavgl_strchr(name, ','); if (end != NULL) { *end = '\0'; } else { - end = name + strlen(name); + end = name + lv_strlen(name); } char *trim = end - 1; diff --git a/src/fs.c b/src/fs.c index e95f25c..4deec5e 100644 --- a/src/fs.c +++ b/src/fs.c @@ -47,10 +47,10 @@ static int luavgl_fs_open(lua_State *L) f->closed = false; lv_fs_mode_t lmode = 0; - if (strchr(mode, 'r')) + if (luavgl_strchr(mode, 'r')) lmode |= LV_FS_MODE_RD; - if (strchr(mode, 'w')) + if (luavgl_strchr(mode, 'w')) lmode |= LV_FS_MODE_WR; lv_fs_res_t res = lv_fs_open(&f->file, path, lmode); diff --git a/src/luavgl.c b/src/luavgl.c index ce11b20..0b2290f 100644 --- a/src/luavgl.c +++ b/src/luavgl.c @@ -42,7 +42,7 @@ LUALIB_API luavgl_ctx_t *luavgl_context(lua_State *L) /* create it if not exist in registry */ lua_pushstring(L, luavglgl_key); ctx = (luavgl_ctx_t *)lua_newuserdata(L, sizeof(*ctx)); - memset(ctx, 0, sizeof(*ctx)); + lv_memset(ctx, 0, sizeof(*ctx)); lua_rawset(L, LUA_REGISTRYINDEX); } else { ctx = (luavgl_ctx_t *)lua_touserdata(L, -1); diff --git a/src/obj.c b/src/obj.c index 2a25d61..15dddb8 100644 --- a/src/obj.c +++ b/src/obj.c @@ -866,7 +866,7 @@ LUALIB_API luavgl_obj_t *luavgl_add_lobj(lua_State *L, lv_obj_t *obj) lua_setmetatable(L, -2); - memset(lobj, 0, sizeof(*lobj)); + lv_memset(lobj, 0, sizeof(*lobj)); lobj->obj = obj; /* Init event array to store events added from lua. */ diff --git a/src/private.h b/src/private.h index 5484e73..51a4625 100644 --- a/src/private.h +++ b/src/private.h @@ -6,7 +6,6 @@ #include #include -#include static void dumpstack(lua_State *L); static void dumptable(lua_State *L, int index); diff --git a/src/style.c b/src/style.c index 7599b8a..95c9f36 100644 --- a/src/style.c +++ b/src/style.c @@ -198,27 +198,47 @@ static lv_flex_align_t luavgl_to_flex_align(lua_State *L, int idx) return LV_FLEX_ALIGN_START; const char *str = lua_tostring(L, idx); - if (strcmp("flex-start", str) == 0) + if (lv_strcmp("flex-start", str) == 0) return LV_FLEX_ALIGN_START; - if (strcmp("flex-end", str) == 0) + if (lv_strcmp("flex-end", str) == 0) return LV_FLEX_ALIGN_END; - if (strcmp("center", str) == 0) + if (lv_strcmp("center", str) == 0) return LV_FLEX_ALIGN_CENTER; - if (strcmp("space-evenly", str) == 0) + if (lv_strcmp("space-evenly", str) == 0) return LV_FLEX_ALIGN_SPACE_EVENLY; - if (strcmp("space-around", str) == 0) + if (lv_strcmp("space-around", str) == 0) return LV_FLEX_ALIGN_SPACE_AROUND; - if (strcmp("space-between", str) == 0) + if (lv_strcmp("space-between", str) == 0) return LV_FLEX_ALIGN_SPACE_BETWEEN; return LV_FLEX_ALIGN_START; } +static char *luavgl_strstr(const char *haystack, const char *needle) { + while (*haystack != '\0') { + const char *h = haystack; + const char *n = needle; + + while (*n != '\0' && *h == *n) { + h++; + n++; + } + + if (*n == '\0') { + return (char *)haystack; + } + + haystack++; + } + + return NULL; +} + static int luavgl_set_flex_layout_kv(lua_State *L, style_set_cb_t cb, void *args) { @@ -239,14 +259,14 @@ static int luavgl_set_flex_layout_kv(lua_State *L, style_set_cb_t cb, if (lua_type(L, -1) == LUA_TSTRING) { str = lua_tostring(L, -1); /* starts with */ - if (strncmp("row", str, 3) == 0) { + if (lv_strcmp("row", str) == 0) { flow = LV_FLEX_FLOW_ROW; - } else if (strncmp("column", str, 3) == 0) { + } else if (lv_strcmp("column", str) == 0) { flow = LV_FLEX_FLOW_COLUMN; } /* if reverse presents */ - if (strstr(str, "-reverse")) { + if (luavgl_strstr(str, "-reverse")) { flow |= _LV_FLEX_REVERSE; } } @@ -259,9 +279,9 @@ static int luavgl_set_flex_layout_kv(lua_State *L, style_set_cb_t cb, lua_getfield(L, -1, "flex_wrap"); if (lua_type(L, -1) == LUA_TSTRING) { str = lua_tostring(L, -1); - if (strcmp("wrap", str) == 0) { + if (lv_strcmp("wrap", str) == 0) { flow |= _LV_FLEX_WRAP; - } else if (strcmp("wrap-reverse", str) == 0) { + } else if (lv_strcmp("wrap-reverse", str) == 0) { flow |= _LV_FLEX_WRAP | _LV_FLEX_REVERSE; } /* else: normal */ @@ -321,7 +341,7 @@ static inline bool luavgl_is_style_inherit(lua_State *L) { const char *str; return (lua_type(L, -1) == LUA_TSTRING) && (str = lua_tostring(L, -1)) && - (strcmp(str, "inherit") == 0); + (lv_strcmp(str, "inherit") == 0); } /** @@ -343,7 +363,7 @@ static int luavgl_set_style_kv(lua_State *L, style_set_cb_t cb, void *args) lv_style_value_t value = {0}; const struct style_map_s *p = NULL; for (int i = 0; i < STYLE_MAP_LEN; i++) { - if (strcmp(key, g_style_map[i].name) == 0) { + if (lv_strcmp(key, g_style_map[i].name) == 0) { p = &g_style_map[i]; break; } @@ -548,7 +568,7 @@ static int luavgl_style_remove_prop(lua_State *L) for (int i = 0; i < STYLE_MAP_LEN; i++) { const struct style_map_s *p = &g_style_map[i]; - if (strcmp(name, p->name) == 0) { + if (lv_strcmp(name, p->name) == 0) { lv_style_remove_prop(&s->style, p->prop); return 0; } diff --git a/src/util.c b/src/util.c index 05cdc60..26218e6 100644 --- a/src/util.c +++ b/src/util.c @@ -296,7 +296,7 @@ LUALIB_API lv_color_t luavgl_tocolor(lua_State *L, int idx) return color; } - int len = strlen(s); + int len = lv_strlen(s); if (len == 4 && s[0] == '#') { /* #RGB */ int r = to_int(s[1]); @@ -370,7 +370,7 @@ LUALIB_API int luavgl_set_property_array(lua_State *L, void *obj, for (int i = 0; i < len; i++) { const luavgl_value_setter_t *p = &table[i]; - if (strcmp(key, p->key)) + if (lv_strcmp(key, p->key)) continue; if (p->type == SETTER_TYPE_INT) { diff --git a/src/widgets/dropdown.c b/src/widgets/dropdown.c index d9ccf47..d2bcfc0 100644 --- a/src/widgets/dropdown.c +++ b/src/widgets/dropdown.c @@ -72,7 +72,7 @@ static int luavgl_dropdown_get(lua_State *L) } const char *key = lua_tostring(L, 2); - if (strcmp(key, "list") == 0) { + if (lv_strcmp(key, "list") == 0) { lv_obj_t *list = lv_dropdown_get_list(obj); lua_pushlightuserdata(L, list); lua_rawget(L, LUA_REGISTRYINDEX); @@ -83,27 +83,27 @@ static int luavgl_dropdown_get(lua_State *L) return 1; } - if (strcmp(key, "text") == 0) { + if (lv_strcmp(key, "text") == 0) { lua_pushstring(L, lv_dropdown_get_text(obj)); return 1; } - if (strcmp(key, "options") == 0) { + if (lv_strcmp(key, "options") == 0) { lua_pushstring(L, lv_dropdown_get_options(obj)); return 1; } - if (strcmp(key, "selected") == 0) { + if (lv_strcmp(key, "selected") == 0) { lua_pushinteger(L, lv_dropdown_get_selected(obj)); return 1; } - if (strcmp(key, "option_cnt") == 0) { + if (lv_strcmp(key, "option_cnt") == 0) { lua_pushinteger(L, lv_dropdown_get_option_cnt(obj)); return 1; } - if (strcmp(key, "selected_str") == 0) { + if (lv_strcmp(key, "selected_str") == 0) { char buf[64]; lv_dropdown_get_selected_str(obj, buf, sizeof(buf)); lua_pushstring(L, buf); @@ -111,19 +111,19 @@ static int luavgl_dropdown_get(lua_State *L) } #if LV_VERSION_CHECK(8, 3, 0) - if (strcmp(key, "option_index") == 0) { + if (lv_strcmp(key, "option_index") == 0) { const char *option = lua_tostring(L, 3); lua_pushinteger(L, lv_dropdown_get_option_index(obj, option)); return 1; } #endif - if (strcmp(key, "symbol") == 0) { + if (lv_strcmp(key, "symbol") == 0) { lua_pushlightuserdata(L, (void *)lv_dropdown_get_symbol(obj)); return 1; } - if (strcmp(key, "dir") == 0) { + if (lv_strcmp(key, "dir") == 0) { lua_pushinteger(L, lv_dropdown_get_dir(obj)); return 1; }