Skip to content

Commit b33be92

Browse files
authored
fix(obj): compatible with lua 5.1 (#81)
* fix(obj): compatible with lua 5.1
1 parent a21ff2c commit b33be92

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/obj.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ static void obj_delete_cb(lv_event_t *e)
2222
goto pop_exit;
2323
}
2424

25+
#if (LUA_VERSION_NUM >= 502)
2526
lua_pushnil(L);
2627
lua_setuservalue(L, -2);
28+
#else
29+
lua_pushglobaltable(L);
30+
lua_setuservalue(L, -2);
31+
#endif
2732

2833
luavgl_obj_t *lobj = luavgl_to_lobj(L, -1);
2934
if (lobj->lua_created)
@@ -860,13 +865,25 @@ static int obj_property_h(lua_State *L, lv_obj_t *obj, bool set)
860865

861866
static int obj_property_user_data(lua_State *L, lv_obj_t *obj, bool set)
862867
{
868+
#if (LUA_VERSION_NUM >= 502)
863869
if (set) {
864870
lua_pushvalue(L, -1);
865871
lua_setuservalue(L, 1);
866872
} else {
867873
lua_getuservalue(L, 1);
868874
}
869875
return 1;
876+
#else
877+
if (set) {
878+
lua_getuservalue(L, 1);
879+
lua_pushvalue(L, -1);
880+
lua_rawseti(L, -2, 1);
881+
} else {
882+
lua_getuservalue(L, 1);
883+
lua_rawgeti(L, -1, 1);
884+
}
885+
return 1;
886+
#endif
870887
}
871888

872889
static const luavgl_property_ops_t obj_property_ops[] = {
@@ -1155,6 +1172,11 @@ LUALIB_API luavgl_obj_t *luavgl_add_lobj(lua_State *L, lv_obj_t *obj)
11551172
lua_pushvalue(L, -2);
11561173
lua_rawset(L, LUA_REGISTRYINDEX);
11571174

1175+
#if (LUA_VERSION_NUM == 501)
1176+
lua_newtable(L);
1177+
lua_setuservalue(L, -2);
1178+
#endif
1179+
11581180
LV_LOG_INFO("add obj: %p to lua, lobj: %p", obj, lua_touserdata(L, -1));
11591181
return lobj;
11601182
}

0 commit comments

Comments
 (0)