diff options
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 109 |
1 files changed, 62 insertions, 47 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 5c79138..c158a61 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c | |||
@@ -670,6 +670,34 @@ qLua *qLuaGet(qtreetbl_t *tree, char *key) | |||
670 | return (qLua *) tree->get(tree, key, NULL, false); | 670 | return (qLua *) tree->get(tree, key, NULL, false); |
671 | } | 671 | } |
672 | 672 | ||
673 | void dumpLuaTree(qtreetbl_t *tree, char *name, int depth) | ||
674 | { | ||
675 | qtreetbl_obj_t obj0; | ||
676 | |||
677 | if (0 == depth) | ||
678 | fprintf(stderr, "DUMP Lua table %s -\n%s =\n{\n", name, name); | ||
679 | else | ||
680 | fprintf(stderr, "%*s[%s] =\n%*s{\n", depth * 2, "", name, depth * 2, ""); | ||
681 | memset((void*)&obj0, 0, sizeof(obj0)); // must be cleared before call | ||
682 | tree->lock(tree); // lock it when thread condition is expected | ||
683 | while(tree->getnext(tree, &obj0, false) == true) | ||
684 | { | ||
685 | qLua *q0 = obj0.data; | ||
686 | |||
687 | switch (q0->type) | ||
688 | { | ||
689 | case LUA_TBOOLEAN : {fprintf(stderr, "%*s[%s] = %d,\n", (depth + 1) * 2, "", obj0.name, q0->v.b); break;} | ||
690 | case LUA_TINTEGER : {fprintf(stderr, "%*s[%s] = %d,\n", (depth + 1) * 2, "", obj0.name, q0->v.i); break;} | ||
691 | case LUA_TNUMBER : {fprintf(stderr, "%*s[%s] = %f,\n", (depth + 1) * 2, "", obj0.name, q0->v.f); break;} | ||
692 | case LUA_TSTRING : {fprintf(stderr, "%*s[%s] = %s,\n", (depth + 1) * 2, "", obj0.name, q0->v.s); break;} | ||
693 | case LUA_TTABLE : {dumpLuaTree(q0->v.t, obj0.name, depth + 1); break;} | ||
694 | default : {fprintf(stderr, "%*s[%s] ? %s,\n", (depth + 1) * 2, "", obj0.name, q0->v.s); break;} | ||
695 | } | ||
696 | } | ||
697 | tree->unlock(tree); | ||
698 | fprintf(stderr, "%*s},\n", depth * 2, ""); | ||
699 | } | ||
700 | |||
673 | qtreetbl_t *lua2tree() | 701 | qtreetbl_t *lua2tree() |
674 | { | 702 | { |
675 | qtreetbl_t *ret = qtreetbl(0); | 703 | qtreetbl_t *ret = qtreetbl(0); |
@@ -686,9 +714,19 @@ qtreetbl_t *lua2tree() | |||
686 | lua_pushvalue(L, -2); | 714 | lua_pushvalue(L, -2); |
687 | // stack now contains: -1 => key; -2 => value; -3 => key; -4 => table | 715 | // stack now contains: -1 => key; -2 => value; -3 => key; -4 => table |
688 | char *n = (char *) lua_tostring(L, -1); // 0, modifies key copy | 716 | char *n = (char *) lua_tostring(L, -1); // 0, modifies key copy |
717 | int t = lua_type(L, -3); | ||
718 | |||
719 | // Correct the sort order. Assuming we will never have more than 999,999 sims. Think that's a safe assumption. | ||
720 | /* https://www.hypergridbusiness.com/2021/07/opensim-land-growth/ | ||
721 | "Total area increased by the equivalent of 2,252 standard regions, for a new record high of 103,625 regions. | ||
722 | That’s nearly four times the area of Second Life," | ||
723 | */ | ||
724 | if ((LUA_TINTEGER == t) || (LUA_TNUMBER == t)) | ||
725 | { | ||
726 | char *tmp = xmprintf("%6s", n); | ||
727 | n = tmp; | ||
728 | } | ||
689 | q.type = lua_type(L, -2); // 0 | 729 | q.type = lua_type(L, -2); // 0 |
690 | // Numbers can convert to strings, so check for numbers before checking for strings. | ||
691 | // On the other hand, strings that can be converted to numbers also pass lua_isnumber(). sigh | ||
692 | switch(q.type) | 730 | switch(q.type) |
693 | { | 731 | { |
694 | case LUA_TBOOLEAN : {q.v.b = lua_toboolean(L, -2); break;} | 732 | case LUA_TBOOLEAN : {q.v.b = lua_toboolean(L, -2); break;} |
@@ -705,6 +743,8 @@ qtreetbl_t *lua2tree() | |||
705 | } | 743 | } |
706 | } | 744 | } |
707 | ret->put(ret, n, &q, sizeof(qLua)); | 745 | ret->put(ret, n, &q, sizeof(qLua)); |
746 | if ((LUA_TINTEGER == t) || (LUA_TNUMBER == t)) | ||
747 | free(n); | ||
708 | // pop value + copy of key, leaving original key | 748 | // pop value + copy of key, leaving original key |
709 | lua_pop(L, 2); // -2 value and copy of key | 749 | lua_pop(L, 2); // -2 value and copy of key |
710 | // stack now contains: -1 => key; -2 => table | 750 | // stack now contains: -1 => key; -2 => table |
@@ -752,6 +792,23 @@ qtreetbl_t *Lua2tree(char *file, char *var) | |||
752 | return ret; | 792 | return ret; |
753 | } | 793 | } |
754 | 794 | ||
795 | void freeLuaTree(qtreetbl_t *tree) | ||
796 | { | ||
797 | qtreetbl_obj_t obj0; | ||
798 | |||
799 | memset((void*)&obj0, 0, sizeof(obj0)); // must be cleared before call | ||
800 | tree->lock(tree); // lock it when thread condition is expected | ||
801 | while(tree->getnext(tree, &obj0, false) == true) | ||
802 | { | ||
803 | qLua *q0 = obj0.data; | ||
804 | |||
805 | if (LUA_TTABLE == q0->type) | ||
806 | freeLuaTree(q0->v.t); | ||
807 | } | ||
808 | tree->unlock(tree); | ||
809 | tree->free(tree); | ||
810 | } | ||
811 | |||
755 | 812 | ||
756 | int Lua2hashtbl(char *file, qhashtbl_t *hash, char *var) | 813 | int Lua2hashtbl(char *file, qhashtbl_t *hash, char *var) |
757 | { | 814 | { |
@@ -815,6 +872,7 @@ int Lua2hashtbl(char *file, qhashtbl_t *hash, char *var) | |||
815 | return ret; | 872 | return ret; |
816 | } | 873 | } |
817 | 874 | ||
875 | |||
818 | int LuaToHash(reqData *Rd, char *file, char *var, qhashtbl_t *tnm, int ret, struct stat *st, struct timespec *now, char *type) | 876 | int LuaToHash(reqData *Rd, char *file, char *var, qhashtbl_t *tnm, int ret, struct stat *st, struct timespec *now, char *type) |
819 | { | 877 | { |
820 | struct timespec then; | 878 | struct timespec then; |
@@ -1154,51 +1212,7 @@ simList *getSims() | |||
1154 | size_t l = strlen(tnm); | 1212 | size_t l = strlen(tnm); |
1155 | 1213 | ||
1156 | ourSims->simsLua = Lua2tree(file, "sims"); | 1214 | ourSims->simsLua = Lua2tree(file, "sims"); |
1157 | 1215 | dumpLuaTree(ourSims->simsLua, "simsLua", 0); | |
1158 | fprintf(stderr, "DEBUG simsLua table\n"); | ||
1159 | qtreetbl_obj_t obj0; | ||
1160 | |||
1161 | memset((void*)&obj0, 0, sizeof(obj0)); // must be cleared before call | ||
1162 | ourSims->simsLua->lock(ourSims->simsLua); // lock it when thread condition is expected | ||
1163 | while(ourSims->simsLua->getnext(ourSims->simsLua, &obj0, false) == true) | ||
1164 | { | ||
1165 | fprintf(stderr, "%s\n", obj0.name); | ||
1166 | qLua *q0 = obj0.data; | ||
1167 | |||
1168 | switch (q0->type) | ||
1169 | { | ||
1170 | case LUA_TBOOLEAN : {fprintf(stderr, " %s = %d\n", obj0.name, q0->v.b); break;} | ||
1171 | case LUA_TINTEGER : {fprintf(stderr, " %s = %d\n", obj0.name, q0->v.i); break;} | ||
1172 | case LUA_TNUMBER : {fprintf(stderr, " %s = %f\n", obj0.name, q0->v.f); break;} | ||
1173 | case LUA_TSTRING : {fprintf(stderr, " %s = %s\n", obj0.name, q0->v.s); break;} | ||
1174 | case LUA_TTABLE : {fprintf(stderr, " %s TABLE\n", obj0.name); break;} | ||
1175 | default : {fprintf(stderr, " %s ? %s\n", obj0.name, q0->v.s); break;} | ||
1176 | } | ||
1177 | if (LUA_TTABLE == q0->type) | ||
1178 | { | ||
1179 | qtreetbl_t *t = q0->v.t; | ||
1180 | qtreetbl_obj_t obj1; | ||
1181 | |||
1182 | memset((void*)&obj1, 0, sizeof(obj1)); // must be cleared before call | ||
1183 | t->lock(t); // lock it when thread condition is expected | ||
1184 | while(t->getnext(t, &obj1, false) == true) | ||
1185 | { | ||
1186 | qLua *q1 = obj1.data; | ||
1187 | switch (q1->type) | ||
1188 | { | ||
1189 | case LUA_TBOOLEAN : {fprintf(stderr, " %s = %d\n", obj1.name, q1->v.b); break;} | ||
1190 | case LUA_TINTEGER : {fprintf(stderr, " %s = %d\n", obj1.name, q1->v.i); break;} | ||
1191 | case LUA_TNUMBER : {fprintf(stderr, " %s = %f\n", obj1.name, q1->v.f); break;} | ||
1192 | case LUA_TSTRING : {fprintf(stderr, " %s = %s\n", obj1.name, q1->v.s); break;} | ||
1193 | case LUA_TTABLE : {fprintf(stderr, " %s TABLE\n", obj1.name); break;} | ||
1194 | default : {fprintf(stderr, " %s ? %s\n", obj1.name, q1->v.s); break;} | ||
1195 | } | ||
1196 | } | ||
1197 | t->unlock(t); | ||
1198 | } | ||
1199 | } | ||
1200 | ourSims->simsLua->unlock(ourSims->simsLua); | ||
1201 | |||
1202 | 1216 | ||
1203 | if (s) | 1217 | if (s) |
1204 | { | 1218 | { |
@@ -1362,6 +1376,7 @@ void freeSimList(simList *sims) | |||
1362 | } | 1376 | } |
1363 | sims->byTab->unlock(sims->byTab); | 1377 | sims->byTab->unlock(sims->byTab); |
1364 | sims->byTab->free(sims->byTab); | 1378 | sims->byTab->free(sims->byTab); |
1379 | freeLuaTree(sims->simsLua); | ||
1365 | 1380 | ||
1366 | free(sims); | 1381 | free(sims); |
1367 | } | 1382 | } |