aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authoronefang2021-09-14 14:23:12 +1000
committeronefang2021-09-14 14:23:12 +1000
commit9253ed37ba124726f1ea1713bf9357553e70e988 (patch)
treed922136cab4977db43cd27ab9b0e9759e49fd586
parentTODO++ (diff)
downloadopensim-SC-9253ed37ba124726f1ea1713bf9357553e70e988.zip
opensim-SC-9253ed37ba124726f1ea1713bf9357553e70e988.tar.gz
opensim-SC-9253ed37ba124726f1ea1713bf9357553e70e988.tar.bz2
opensim-SC-9253ed37ba124726f1ea1713bf9357553e70e988.tar.xz
Better Lua type decoding.
-rw-r--r--src/sledjchisl/sledjchisl.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c
index 08d0092..65d868c 100644
--- a/src/sledjchisl/sledjchisl.c
+++ b/src/sledjchisl/sledjchisl.c
@@ -1007,16 +1007,41 @@ int Lua2hashtbl(char *file, qhashtbl_t *hash, char *var)
1007 while(lua_next(L, -2) != 0) // -1 key, +2 next key, value (or 0 if nothing left in table) 1007 while(lua_next(L, -2) != 0) // -1 key, +2 next key, value (or 0 if nothing left in table)
1008 { 1008 {
1009 char *n = (char *) lua_tostring(L, -2); // 0 1009 char *n = (char *) lua_tostring(L, -2); // 0
1010 int type = lua_type(L, -1); // 0
1010 1011
1012
1013 switch(type)
1014 {
1015 case LUA_TBOOLEAN :
1016 case LUA_TINTEGER :
1017 case LUA_TNUMBER :
1018 {
1019 float v = lua_tonumber(L, -1); // 0
1020 hash->put(hash, n, &v, sizeof(float));
1021 break;
1022 }
1023 case LUA_TSTRING :
1024 {
1025 hash->putstr(hash, n, (char *) lua_tostring(L, -1)); // 0
1026 break;
1027 }
1028
1029 default :
1030 {
1031 char *v = (char *) lua_tostring(L, -1); // 0
1032 E("Unknown Lua variable type for %s = %s", n, v);
1033 break;
1034 }
1035 }
1036/*
1011 // Numbers can convert to strings, so check for numbers before checking for strings. 1037 // Numbers can convert to strings, so check for numbers before checking for strings.
1012 // On the other hand, strings that can be converted to numbers also pass lua_isnumber(). sigh 1038 // On the other hand, strings that can be converted to numbers also pass lua_isnumber(). sigh
1013/* if (lua_isnumber(L, -1)) // 0 1039 if (lua_isnumber(L, -1)) // 0
1014 { 1040 {
1015 float v = lua_tonumber(L, -1); // 0 1041 float v = lua_tonumber(L, -1); // 0
1016 hash->put(hash, n, &v, sizeof(float)); 1042 hash->put(hash, n, &v, sizeof(float));
1017 } 1043 }
1018 else 1044 else
1019*/
1020 if (lua_isstring(L, -1)) // 0 1045 if (lua_isstring(L, -1)) // 0
1021 hash->putstr(hash, n, (char *) lua_tostring(L, -1)); // 0 1046 hash->putstr(hash, n, (char *) lua_tostring(L, -1)); // 0
1022 else if (lua_isboolean(L, -1)) // 0 1047 else if (lua_isboolean(L, -1)) // 0
@@ -1029,6 +1054,7 @@ int Lua2hashtbl(char *file, qhashtbl_t *hash, char *var)
1029 char *v = (char *) lua_tostring(L, -1); // 0 1054 char *v = (char *) lua_tostring(L, -1); // 0
1030 E("Unknown Lua variable type for %s = %s", n, v); 1055 E("Unknown Lua variable type for %s = %s", n, v);
1031 } 1056 }
1057*/
1032 lua_pop(L, 1); // -1 value 1058 lua_pop(L, 1); // -1 value
1033 } 1059 }
1034 lua_pop(L, 1); // -1 var 1060 lua_pop(L, 1); // -1 var