Sfoglia il codice sorgente

Changed the print function to behave like the Lua print, accepting multiple parameters, printing then tab separated and adding a new line, the original print is now called "print1" because it only prints one element.

mingodad 13 anni fa
parent
commit
e0e098e406
1 ha cambiato i file con 21 aggiunte e 2 eliminazioni
  1. 21 2
      squirrel/sqbaselib.cpp

+ 21 - 2
squirrel/sqbaselib.cpp

@@ -182,7 +182,7 @@ static SQInteger get_slice_params(HSQUIRRELVM v,SQInteger &sidx,SQInteger &eidx,
 	return 1;
 }
 
-static SQInteger base_print(HSQUIRRELVM v)
+static SQInteger base_print1(HSQUIRRELVM v)
 {
 	const SQChar *str;
 	sq_tostring(v,2);
@@ -191,6 +191,24 @@ static SQInteger base_print(HSQUIRRELVM v)
 	return 0;
 }
 
+static SQInteger base_print(HSQUIRRELVM v)
+{
+    if(_ss(v)->_printfunc){
+        SQPRINTFUNCTION sqprint = _ss(v)->_printfunc;
+        const SQChar *str;
+        SQInteger nargs=sq_gettop(v);
+        for(int i=2; i<=nargs; ++i){
+            if(i>2) sqprint(v,_SC("\t"));
+            sq_tostring(v,i);
+            sq_getstring(v,-1,&str);
+            sqprint(v,_SC("%s"),str);
+            sq_poptop(v); //remove converted string
+        }
+        sqprint(v,_SC("\n"));
+    }
+	return 0;
+}
+
 static SQInteger base_error(HSQUIRRELVM v)
 {
 	const SQChar *str;
@@ -273,7 +291,8 @@ static SQRegFunction base_funcs[]={
 	{_SC("getconsttable"),base_getconsttable,1, NULL},
 	{_SC("setconsttable"),base_setconsttable,2, NULL},
 	{_SC("assert"),base_assert,2, NULL},
-	{_SC("print"),base_print,2, NULL},
+	{_SC("print1"),base_print1,2, NULL},
+	{_SC("print"),base_print,-2, NULL},
 	{_SC("error"),base_error,2, NULL},
 	{_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
 	{_SC("newthread"),base_newthread,2, _SC(".c")},