summaryrefslogtreecommitdiff
path: root/src/emap/script_buildins.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emap/script_buildins.c')
-rw-r--r--src/emap/script_buildins.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/emap/script_buildins.c b/src/emap/script_buildins.c
index 703307a..2b65f4a 100644
--- a/src/emap/script_buildins.c
+++ b/src/emap/script_buildins.c
@@ -24,6 +24,7 @@
#include "emap/lang.h"
#include "emap/map.h"
#include "emap/hashtable.h"
+#include "emap/judyarray.h"
#include "emap/scriptdefines.h"
#include "emap/send.h"
#include "emap/data/bgd.h"
@@ -42,6 +43,114 @@ uint32 MakeDWord(uint16 word0, uint16 word1)
return ((uint32)(word0)) | ((uint32)(word1 << 0x10));
}
+BUILDIN(judyNew)
+{
+ int64 id = judy->new_array();
+ script_pushint(st, id);
+ return true;
+}
+
+BUILDIN(judyPut)
+{
+ int64 id = script_getnum(st, 2);
+ const char *key = script_getstr(st, 3);
+ struct DBData *value;
+
+ CREATE(value, struct DBData, 1);
+
+ if (script_isstringtype(st, 4))
+ {
+ value->type = DB_DATA_PTR;
+ value->u.ptr = (void *)aStrdup(script_getstr(st, 4));
+ }
+ else if (script_isinttype(st, 4))
+ {
+ value->type = DB_DATA_INT;
+ value->u.i = script_getnum(st, 4);
+ }
+ else
+ {
+ aFree(value);
+ ShowError("judy_put: unhandled data type!\n");
+ script_pushint(st, 0);
+ return false;
+ }
+
+ judy->setvalue(id, key, value);
+ script_pushint(st, 1);
+ return true;
+}
+
+BUILDIN(judyGet)
+{
+ struct DBData defval_s;
+ struct DBData *defval = &defval_s;
+ int64 id = script_getnum(st, 2);
+ const char *key = script_getstr(st, 3);
+
+ if (script_hasdata(st, 4))
+ {
+ if (script_isstringtype(st, 4))
+ {
+ defval->type = DB_DATA_PTR;
+ defval->u.ptr = (void*)script_getstr(st, 4);
+ }
+ else if (script_isinttype(st, 4))
+ {
+ defval->type = DB_DATA_INT;
+ defval->u.i = script_getnum(st, 4);
+ }
+ else
+ {
+ ShowError("usage: judy_get(<id>, <strkey>[ ,<defval>])\n");
+ return false;
+ }
+ }
+ else
+ {
+ defval = NULL;
+ }
+
+ const struct DBData *result = judy->getvalue(id, key, defval);
+ if (result)
+ {
+ switch(result->type)
+ {
+ case DB_DATA_INT:
+ case DB_DATA_UINT:
+ script_pushint(st, result->u.i);
+ break;
+ case DB_DATA_PTR:
+ script_pushstrcopy(st, result->u.ptr);
+ break;
+ }
+ }
+ else
+ {
+ script_pushint(st, 0);
+ }
+
+ return true;
+}
+
+BUILDIN(judySize)
+{
+ script_pushint(st, judy->array_size(script_getnum(st, 2)));
+ return true;
+}
+
+BUILDIN(judyExists)
+{
+ script_pushint(st, judy->array_exists(script_getnum(st, 2)));
+ return true;
+}
+
+BUILDIN(judyFree)
+{
+ script_pushint(st, judy->destroy_array(script_getnum(st, 2)));
+ return true;
+}
+
BUILDIN(l)
{
format_sub(st, 1);