aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Controller-afb/ctl-lua.c44
-rw-r--r--nbproject/configurations.xml146
2 files changed, 115 insertions, 75 deletions
diff --git a/Controller-afb/ctl-lua.c b/Controller-afb/ctl-lua.c
index 2aaa3a5..acadfb9 100644
--- a/Controller-afb/ctl-lua.c
+++ b/Controller-afb/ctl-lua.c
@@ -165,26 +165,50 @@ STATIC int LuaPushArgument (json_object *argsJ) {
STATIC json_object *LuaPopOneArg (lua_State* luaState, int idx);
+// Move a table from Internal Lua representation to Json one
+// Numeric table are transformed in json array, string one in object
+// Mix numeric/string key are not supported
STATIC json_object *LuaTableToJson (lua_State* luaState, int index) {
- int idx;
#define LUA_KEY_INDEX -2
#define LUA_VALUE_INDEX -1
+
+ int idx;
+ int tableType;
+ json_object *tableJ= NULL;
- json_object *tableJ= json_object_new_object();
- const char *key;
- char number[3];
lua_pushnil(luaState); // 1st key
if (index < 0) index--;
for (idx=1; lua_next(luaState, index) != 0; idx++) {
// uses 'key' (at index -2) and 'value' (at index -1)
- if (lua_type(luaState,LUA_KEY_INDEX) == LUA_TSTRING) key= lua_tostring(luaState, LUA_KEY_INDEX);
- else {
- snprintf(number, sizeof(number),"%d", idx);
- key=number;
+ if (lua_type(luaState,LUA_KEY_INDEX) == LUA_TSTRING) {
+
+ if (!tableJ) {
+ tableJ= json_object_new_object();
+ tableType=LUA_TSTRING;
+ } else if (tableType != LUA_TSTRING){
+ AFB_ERROR("MIX Lua Table with key string/numeric not supported");
+ return NULL;
+ }
+
+ const char *key= lua_tostring(luaState, LUA_KEY_INDEX);
+ json_object *argJ= LuaPopOneArg(luaState, LUA_VALUE_INDEX);
+ json_object_object_add(tableJ, key, argJ);
+
+ } else {
+ if (!tableJ) {
+ tableJ= json_object_new_array();
+ tableType=LUA_TNUMBER;
+ } else if(tableType == LUA_TNUMBER) {
+ AFB_ERROR("MIX Lua Table with key string/numeric not supported");
+ return NULL;
+ }
+
+ json_object *argJ= LuaPopOneArg(luaState, LUA_VALUE_INDEX);
+ json_object_array_add(tableJ, argJ);
}
- json_object *argJ= LuaPopOneArg(luaState, LUA_VALUE_INDEX);
- json_object_object_add(tableJ, key, argJ);
+
+
lua_pop(luaState, 1); // removes 'value'; keeps 'key' for next iteration
}
diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml
index 3501376..424cd2f 100644
--- a/nbproject/configurations.xml
+++ b/nbproject/configurations.xml
@@ -166,35 +166,83 @@
</cTool>
</item>
<item path="Alsa-afb/Alsa-AddCtl.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/alsa</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>Audio-Common</pElem>
+ <pElem>../../../opt/include</pElem>
+ <pElem>build/Alsa-afb</pElem>
+ </incDir>
</cTool>
</item>
<item path="Alsa-afb/Alsa-ApiHat.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>build/Alsa-afb</pElem>
+ </incDir>
</cTool>
</item>
<item path="Alsa-afb/Alsa-RegEvt.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/alsa</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>Audio-Common</pElem>
+ <pElem>../../../opt/include</pElem>
+ <pElem>build/Alsa-afb</pElem>
+ </incDir>
</cTool>
</item>
<item path="Alsa-afb/Alsa-SetGet.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/alsa</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>Audio-Common</pElem>
+ <pElem>../../../opt/include</pElem>
+ <pElem>build/Alsa-afb</pElem>
+ </incDir>
</cTool>
</item>
<item path="Alsa-afb/Alsa-Ucm.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/alsa</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>Audio-Common</pElem>
+ <pElem>../../../opt/include</pElem>
+ <pElem>build/Alsa-afb</pElem>
+ </incDir>
</cTool>
</item>
<item path="Audio-Common/audio-common.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>Audio-Common</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>build/Audio-Common</pElem>
+ </incDir>
</cTool>
</item>
<item path="Audio-Common/filescan-utils.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>Audio-Common</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>build/Audio-Common</pElem>
+ </incDir>
</cTool>
</item>
<item path="Audio-Common/wrap-json.c" ex="false" tool="0" flavor2="3">
- <cTool flags="0">
+ <cTool flags="3">
+ <incDir>
+ <pElem>Audio-Common</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>build/Audio-Common</pElem>
+ </incDir>
</cTool>
</item>
<item path="Common/AudioCommonLib.c" ex="false" tool="0" flavor2="2">
@@ -224,35 +272,13 @@
</cTool>
</item>
<item path="Controller-afb/ctl-lua.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
- <incDir>
- <pElem>../../../opt/include/afb</pElem>
- <pElem>Controller-afb</pElem>
- <pElem>/usr/include/json-c</pElem>
- <pElem>/usr/include/lua5.3</pElem>
- <pElem>Audio-Common</pElem>
- <pElem>../../../opt/include</pElem>
- <pElem>build/Controller-afb</pElem>
- </incDir>
- </cTool>
- </item>
- <item path="Controller-afb/ctl-misc.c" ex="false" tool="0" flavor2="3">
- <cTool flags="3">
- <incDir>
- <pElem>../../../opt/include/afb</pElem>
- <pElem>Controller-afb</pElem>
- <pElem>/usr/include/json-c</pElem>
- <pElem>build/Controller-afb</pElem>
- </incDir>
- </cTool>
- </item>
- <item path="Controller-afb/ctl-plugin-sample.c" ex="false" tool="0" flavor2="3">
<cTool flags="0">
<incDir>
<pElem>../../../opt/include</pElem>
<pElem>../../../opt/include/alsa</pElem>
<pElem>/usr/include/p11-kit-1</pElem>
<pElem>/usr/include/json-c</pElem>
+ <pElem>/usr/include/lua5.3</pElem>
<pElem>Audio-Common</pElem>
<pElem>build/Controller-afb</pElem>
</incDir>
@@ -272,10 +298,31 @@
<Elem>MAX_SND_CARD=16</Elem>
<Elem>NATIVE_LINUX</Elem>
<Elem>TLV_BYTE_SIZE=256</Elem>
- <Elem>audio_plugin_sample_EXPORTS</Elem>
+ <Elem>control_afb_EXPORTS</Elem>
</preprocessorList>
</cTool>
</item>
+ <item path="Controller-afb/ctl-misc.c" ex="false" tool="0" flavor2="3">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>Controller-afb</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>build/Controller-afb</pElem>
+ </incDir>
+ </cTool>
+ </item>
+ <item path="Controller-afb/ctl-plugin-sample.c" ex="false" tool="0" flavor2="3">
+ <cTool flags="3">
+ <incDir>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>Controller-afb</pElem>
+ <pElem>/usr/include/json-c</pElem>
+ <pElem>/usr/include/lua5.3</pElem>
+ <pElem>build/Controller-afb</pElem>
+ </incDir>
+ </cTool>
+ </item>
<item path="Controller-afb/ctl-timer.c" ex="false" tool="0" flavor2="3">
<cTool flags="3">
<incDir>
@@ -514,40 +561,9 @@
<folder path="0/Alsa-afb">
<cTool>
<incDir>
- <pElem>../../../opt/include</pElem>
- <pElem>../../../opt/include/alsa</pElem>
- <pElem>/usr/include/p11-kit-1</pElem>
- <pElem>/usr/include/json-c</pElem>
- <pElem>Audio-Common</pElem>
- <pElem>build/Alsa-afb</pElem>
- </incDir>
- <preprocessorList>
- <Elem>CONTROL_MAXPATH_LEN=255</Elem>
- <Elem>MAX_LINEAR_DB_SCALE=24</Elem>
- <Elem>MAX_SND_CARD=16</Elem>
- <Elem>NATIVE_LINUX</Elem>
- <Elem>TLV_BYTE_SIZE=256</Elem>
- <Elem>alsa_lowlevel_EXPORTS</Elem>
- </preprocessorList>
- </cTool>
- </folder>
- <folder path="0/Audio-Common">
- <cTool>
- <incDir>
- <pElem>../../../opt/include</pElem>
- <pElem>../../../opt/include/alsa</pElem>
- <pElem>/usr/include/p11-kit-1</pElem>
- <pElem>/usr/include/json-c</pElem>
- <pElem>Audio-Common</pElem>
- <pElem>build/Audio-Common</pElem>
+ <pElem>../../../opt/include/afb</pElem>
+ <pElem>Alsa-afb</pElem>
</incDir>
- <preprocessorList>
- <Elem>CONTROL_MAXPATH_LEN=255</Elem>
- <Elem>MAX_LINEAR_DB_SCALE=24</Elem>
- <Elem>MAX_SND_CARD=16</Elem>
- <Elem>NATIVE_LINUX</Elem>
- <Elem>TLV_BYTE_SIZE=256</Elem>
- </preprocessorList>
</cTool>
</folder>
<folder path="0/Common">