]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - exec.cpp
add variable search order test
[xonotic/gmqcc.git] / exec.cpp
index 17f52f62e5efcb35c673233e93aff702974ff0ff..387923f27b3c9d86f7cf772085ba2740a689087a 100644 (file)
--- a/exec.cpp
+++ b/exec.cpp
@@ -113,7 +113,8 @@ qc_program_t* prog_load(const char *filename, bool skipversion)
     /* spawn the world entity */
     prog->entitypool.emplace_back(true);
     prog->entitydata.resize(prog->entityfields);
-    memset(prog->entitydata.data(), 0, sizeof(prog->entitydata[0]) * prog->entityfields);
+    if (prog->entitydata.size())
+        memset(prog->entitydata.data(), 0, sizeof(prog->entitydata[0]) * prog->entityfields);
     prog->entities = 1;
 
     /* cache some globals and fields from names */
@@ -517,8 +518,10 @@ static qcint_t prog_leavefunction(qc_program_t *prog) {
     oldsp = prog->stack[prog->stack.size()-1].localsp;
 #endif
     if (prev) {
-        qcint_t *globals = &prog->globals[0] + prev->firstlocal;
-        memcpy(globals, &prog->localstack[oldsp], prev->locals * sizeof(prog->localstack[0]));
+        if (prev->locals) {
+            qcint_t *globals = &prog->globals[0] + prev->firstlocal;
+            memcpy(globals, &prog->localstack[oldsp], prev->locals * sizeof(prog->localstack[0]));
+        }
         prog->localstack.resize(oldsp);
     }
 
@@ -668,6 +671,19 @@ static int qc_stof(qc_program_t *prog) {
     return 0;
 }
 
+static int qc_stov(qc_program_t *prog) {
+    qcany_t *str;
+    qcany_t num;
+    CheckArgs(1);
+    str = GetArg(0);
+    (void)util_sscanf(prog_getstring(prog, str->string), " ' %f %f %f ' ",
+                      &num.vector[0],
+                      &num.vector[1],
+                      &num.vector[2]);
+    Return(num);
+    return 0;
+}
+
 static int qc_vtos(qc_program_t *prog) {
     char buffer[512];
     qcany_t *num;
@@ -833,7 +849,8 @@ static prog_builtin_t qc_builtins[] = {
     &qc_normalize,   /*   12  */
     &qc_sqrt,        /*   13  */
     &qc_floor,       /*   14  */
-    &qc_pow          /*   15  */
+    &qc_pow,         /*   15  */
+    &qc_stov         /*   16  */
 };
 
 static const char *arg0 = nullptr;