]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Adding strcat builtin to qcvm
authorWolfgang Bumiller <blub@speed.at>
Sun, 23 Dec 2012 18:05:39 +0000 (19:05 +0100)
committerWolfgang Bumiller <blub@speed.at>
Sun, 23 Dec 2012 18:06:29 +0000 (19:06 +0100)
doc/qcvm.1
exec.c

index 7d1ae8734b98a22dd769e9871c68f092cca88977..1d895956ef7963fd016a3fc1b43b67d5ffe26286 100644 (file)
@@ -83,6 +83,9 @@ Get the entity ID as string.
 .TP
 .RI "9) " float " stof(" string ") = " "#9" ;
 Convert a string to a float.
+.TP
+.RI "10) " string " strcat(" string ", " string ") = " "#10" ;
+Concatenate two strings, returning a tempstring.
 .SH BUGS
 Please report bugs on <http://github.com/graphitemaster/gmqcc/issues>,
 or see <http://graphitemaster.github.com/gmqcc> on how to contact us.
diff --git a/exec.c b/exec.c
index 54201ffe66a0faeca60c28ae7e16b5d985c48959..ca98675945bf89ea007185324cac333f43bd412f 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -744,6 +744,30 @@ static int qc_vlen(qc_program *prog)
     return 0;
 }
 
+static int qc_strcat(qc_program *prog)
+{
+    char  *buffer;
+    size_t len1,   len2;
+    char  *cstr1, *cstr2;
+    qcany *str1,  *str2;
+    qcany  out;
+
+    CheckArgs(2);
+    str1 = GetArg(0);
+    str2 = GetArg(1);
+    cstr1 = prog_getstring(prog, str1->string);
+    cstr2 = prog_getstring(prog, str2->string);
+    len1 = strlen(cstr1);
+    len2 = strlen(cstr2);
+    buffer = (char*)mem_a(len1 + len2 + 1);
+    memcpy(buffer, cstr1, len1);
+    memcpy(buffer+len1, cstr2, len2+1);
+    out.string = prog_tempstring(prog, buffer);
+    mem_d(buffer);
+    Return(out);
+    return 0;
+}
+
 static prog_builtin qc_builtins[] = {
     NULL,
     &qc_print, /*   1   */
@@ -754,7 +778,8 @@ static prog_builtin qc_builtins[] = {
     &qc_error, /*   6   */
     &qc_vlen,  /*   7   */
     &qc_etos,  /*   8   */
-    &qc_stof   /*   9   */
+    &qc_stof,  /*   9   */
+    &qc_strcat /*   10  */
 };
 static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]);