developer | 54127b7 | 2022-07-25 13:16:11 +0800 | [diff] [blame] | 1 | From 24b5aae13f1fe1ae90eab5fbd8e62df72681d065 Mon Sep 17 00:00:00 2001 |
| 2 | From: sah4009 <peter.deherdt@softathome.com> |
| 3 | Date: Mon, 16 Sep 2019 09:22:16 +0000 |
| 4 | Subject: [PATCH] Lua 5.3 support |
| 5 | |
| 6 | --- |
| 7 | lua/CMakeLists.txt | 3 ++- |
| 8 | lua/ubus.c | 23 +++++++++++++++++++---- |
| 9 | 2 files changed, 21 insertions(+), 5 deletions(-) |
| 10 | |
| 11 | diff --git a/lua/CMakeLists.txt b/lua/CMakeLists.txt |
| 12 | index e4821bf..5dae67a 100644 |
| 13 | --- a/lua/CMakeLists.txt |
| 14 | +++ b/lua/CMakeLists.txt |
| 15 | @@ -8,7 +8,7 @@ IF(NOT LUA_CFLAGS) |
| 16 | FIND_PROGRAM(PKG_CONFIG pkg-config) |
| 17 | IF(PKG_CONFIG) |
| 18 | EXECUTE_PROCESS( |
| 19 | - COMMAND pkg-config --silence-errors --cflags lua5.1 |
| 20 | + COMMAND pkg-config --silence-errors --cflags lua5.3 |
| 21 | OUTPUT_VARIABLE LUA_CFLAGS |
| 22 | OUTPUT_STRIP_TRAILING_WHITESPACE |
| 23 | ) |
| 24 | @@ -45,6 +45,7 @@ IF(BUILD_LUA) |
| 25 | PREFIX "" |
| 26 | ) |
| 27 | TARGET_LINK_LIBRARIES(ubus_lua ubus) |
| 28 | + TARGET_LINK_LIBRARIES(ubus_lua -llua) |
| 29 | |
| 30 | INSTALL(TARGETS ubus_lua |
| 31 | LIBRARY DESTINATION ${LUAPATH} |
| 32 | diff --git a/lua/ubus.c b/lua/ubus.c |
| 33 | index 86dcc50..6d7ba00 100644 |
| 34 | --- a/lua/ubus.c |
| 35 | +++ b/lua/ubus.c |
| 36 | @@ -23,6 +23,11 @@ |
| 37 | #define MODNAME "ubus" |
| 38 | #define METANAME MODNAME ".meta" |
| 39 | |
| 40 | +#if LUA_VERSION_NUM > 501 |
| 41 | +#define luaL_optint luaL_optinteger |
| 42 | +#define lua_objlen lua_rawlen |
| 43 | +#endif |
| 44 | + |
| 45 | static lua_State *state; |
| 46 | |
| 47 | struct ubus_lua_connection { |
| 48 | @@ -275,7 +280,7 @@ ubus_lua_objects_cb(struct ubus_context *c, struct ubus_object_data *o, void *p) |
| 49 | lua_State *L = (lua_State *)p; |
| 50 | |
| 51 | lua_pushstring(L, o->path); |
| 52 | - lua_rawseti(L, -2, lua_objlen(L, -2) + 1); |
| 53 | + lua_rawseti(L, -2, lua_rawlen(L, -2) + 1); |
| 54 | } |
| 55 | |
| 56 | static int |
| 57 | @@ -572,11 +577,11 @@ static int ubus_lua_add(lua_State *L) |
| 58 | if (obj){ |
| 59 | ubus_add_object(c->ctx, obj); |
| 60 | |
| 61 | - /* allow future reference of ubus obj */ |
| 62 | + /* allow future reference of ubus obj */ |
| 63 | lua_pushstring(state,"__ubusobj"); |
| 64 | lua_pushlightuserdata(state, obj); |
| 65 | lua_settable(state,-3); |
| 66 | - } |
| 67 | + } |
| 68 | } |
| 69 | lua_pop(L, 1); |
| 70 | } |
| 71 | @@ -973,11 +978,21 @@ luaopen_ubus(lua_State *L) |
| 72 | lua_setfield(L, -2, "__index"); |
| 73 | |
| 74 | /* fill metatable */ |
| 75 | +#if LUA_VERSION_NUM > 501 |
| 76 | + luaL_setfuncs(L, ubus, 0); |
| 77 | +#else |
| 78 | luaL_register(L, NULL, ubus); |
| 79 | - lua_pop(L, 1); |
| 80 | +#endif |
| 81 | |
| 82 | /* create module */ |
| 83 | +#if LUA_VERSION_NUM > 501 |
| 84 | + lua_newtable(L); |
| 85 | + luaL_setfuncs (L, ubus, 0); |
| 86 | + lua_pushvalue(L, -1); |
| 87 | + lua_setglobal(L, MODNAME); |
| 88 | +#else |
| 89 | luaL_register(L, MODNAME, ubus); |
| 90 | +#endif |
| 91 | |
| 92 | /* set some enum defines */ |
| 93 | lua_pushinteger(L, BLOBMSG_TYPE_ARRAY); |
| 94 | -- |
| 95 | 2.26.2 |
| 96 | |