summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-12-04 12:22:57 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2018-12-05 15:22:26 +0100
commit8bef6c3c5dd49b6708c2a0c077ee88ee57a461af (patch)
tree717f046f173b7bc39371535795d70ae92f3f6cab
parent3344fe2a65c5d152d0f8466e5219e0437808ed0b (diff)
Handle number and boolean to subcall an api's verb
An improvment was made to handle string for synchronous subcalls and now it handles also number and boolean for both sync and async subcalls. Change-Id: Iafaf9d01b8abd83423b1809a9e0e5433d44d6ded Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--ctl-lib/ctl-lua.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c
index 08c9b85..b61885d 100644
--- a/ctl-lib/ctl-lua.c
+++ b/ctl-lib/ctl-lua.c
@@ -470,7 +470,7 @@ static int LuaAfbService(lua_State* luaState) {
// get api/verb+query
const char *api = lua_tostring(luaState, 3);
const char *verb = lua_tostring(luaState, 4);
- json_object *queryJ = LuaTableToJson(source, luaState, 5);
+ json_object *queryJ = LuaPopOneArg(source, luaState, LUA_FIRST_ARG + 3);
if (queryJ == JSON_ERROR) return 1;
LuaCbHandleT *handleCb = calloc(1, sizeof (LuaCbHandleT));
@@ -498,7 +498,9 @@ static int LuaAfbServiceSync(lua_State* luaState) {
}
// note: argument start at 2 because of AFB: table
- if (count != 5 || !lua_isstring(luaState, LUA_FIRST_ARG + 1) || !lua_isstring(luaState, LUA_FIRST_ARG + 2) || (!lua_istable(luaState, LUA_FIRST_ARG + 3) && !lua_isstring(luaState, LUA_FIRST_ARG +3))) {
+ if (count != 5 ||
+ ! lua_isstring(luaState, LUA_FIRST_ARG + 1) ||
+ ! lua_isstring(luaState, LUA_FIRST_ARG + 2)) {
lua_pushliteral(luaState, "ERROR: syntax AFB:servsync(source, api, verb, {[Lua Table]})");
lua_error(luaState);
return 1;
@@ -508,12 +510,9 @@ static int LuaAfbServiceSync(lua_State* luaState) {
// get source/api/verb+query
const char *api = lua_tostring(luaState, LUA_FIRST_ARG + 1);
const char *verb = lua_tostring(luaState, LUA_FIRST_ARG + 2);
- json_object *queryJ = NULL;
- if (lua_istable(luaState, LUA_FIRST_ARG + 3)) {
- queryJ = LuaTableToJson(source, luaState, LUA_FIRST_ARG + 3);
- } else {
- queryJ = json_object_new_string(lua_tostring(luaState, LUA_FIRST_ARG + 3));
- }
+
+ json_object *queryJ = LuaPopOneArg(source, luaState, LUA_FIRST_ARG + 3);
+ if (queryJ == JSON_ERROR) return 1;
int iserror = AFB_ServiceSync(source->api, api, verb, queryJ, &responseJ);