diff mbox

[OpenWrt-Devel,v2,3/3] lua: restore return value of require('uci') to module table.

Message ID 1426653885-23455-4-git-send-email-yszhou4tech@gmail.com
State Accepted
Delegated to: Felix Fietkau
Headers show

Commit Message

Yousong Zhou March 18, 2015, 4:44 a.m. UTC
Before commit "b121dd lua: add lua 5.2 compatibility changes", the
module table was filled by luaL_register() which would leave the table
at the top of the stack.  But in current code the module table will be
popped by lua_setglobal() causing the return value defaulting to boolean
value true.

Also fix the return value of luaopen_uci() to 1 to indicate the number
of return value on stack.

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
 lua/uci.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox


diff --git a/lua/uci.c b/lua/uci.c
index 8ace746..6ba7da0 100644
--- a/lua/uci.c
+++ b/lua/uci.c
@@ -994,8 +994,9 @@  luaopen_uci(lua_State *L)
 	/* create module */
+	lua_pushvalue(L, -1);
 	luaL_setfuncs(L, uci, 0);
 	lua_setglobal(L, MODNAME);
-	return 0;
+	return 1;