diff mbox series

lua: return value from scripts not evaluated

Message ID 1515509643-24947-1-git-send-email-sbabic@denx.de
State Accepted
Headers show
Series lua: return value from scripts not evaluated | expand

Commit Message

Stefano Babic Jan. 9, 2018, 2:54 p.m. UTC
After recent factorization, the return value from LUA scripts is
not evaluated because the order of the results on the LUA stack
is wrong.

Signed-off-by: Stefano Babic <sbabic@denx.de>
---
 corelib/lua_interface.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/corelib/lua_interface.c b/corelib/lua_interface.c
index f873aac..abc8352 100644
--- a/corelib/lua_interface.c
+++ b/corelib/lua_interface.c
@@ -185,11 +185,15 @@  int run_lua_script(const char *script, const char *function, char *parms)
 		return -1;
 	}
 
-	if (lua_type(L, 1) == LUA_TBOOLEAN)
-		ret = lua_toboolean(L, 1) ? 0 : 1;
+	ret = -1;
 
-	if (lua_type(L, 2) == LUA_TSTRING) {
-		output = lua_tostring(L, 2);
+	if (lua_type(L, -2) == LUA_TBOOLEAN) {
+		TRACE("LUA Exit: is boolean %d", lua_toboolean(L, -2));
+		ret = lua_toboolean(L, -2) ? 0 : 1;
+	}
+
+	if (lua_type(L, -1) == LUA_TSTRING) {
+		output = lua_tostring(L, -1);
 		TRACE("Script output: %s script end", output);
 	}