Patch #1865 2007-01-31 19:03

arst

With Doc: Scripting console updates with Squirrel shell
Download
1865-With_Doc_Scrip.patch (133.7 KB)
Category
 
Status
Open
Close date
 
Assigned to
mandrav
Index: src/sdk/scripting/sqsession/sqext.cpp
===================================================================
--- src/sdk/scripting/sqsession/sqext.cpp    (revision 0)
+++ src/sdk/scripting/sqsession/sqext.cpp    (revision 0)
@@ -0,0 +1,294 @@
+/* see copyright notice in squirrel.h */
+#include <squirrel.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <ctype.h>
+#include <assert.h>
+
+#include "../squirrel/sqpcheader.h"
+#include "../squirrel/sqvm.h"
+#include "../squirrel/sqclosure.h"
+#include "../squirrel/sqfuncproto.h"
+
+#include "sqext.h"
+
+#ifdef SQUNICODE
+#define scfprintf fwprintf
+#define scfopen    _wfopen
+#define scvprintf vwprintf
+#else
+#define scfprintf fprintf
+#define scfopen    fopen
+#define scvprintf vprintf
+#endif
+
+#ifdef ATS
+extern int g_sq_malloc_n;
+extern int g_sq_malloc_tot;
+extern int g_sq_malloc_oper_sum;
+
+SQInteger _ext_getmemusage(HSQUIRRELVM v){
+    sq_newtable(v);
+    sq_pushstring(v,_SC("nr_blocks"),-1);
+    sq_pushinteger(v,g_sq_malloc_n);
+    sq_rawset(v,-3);
+    sq_pushstring(v,_SC("total_size"),-1);
+    sq_pushinteger(v,g_sq_malloc_tot);
+    sq_rawset(v,-3);
+    sq_pushstring(v,_SC("total_nr_ops"),-1);
+    sq_pushinteger(v,g_sq_malloc_oper_sum);
+    sq_rawset(v,-3);
+    return 1;
+}
+#endif // ifdef ATS
+/*
+void ext_scstrcat( SQChar *dst, const SQChar *src, int *pp ){
+    if( !src ) return;
+    int i, p = *pp;
+    for( i=0; src[i]; i++ )
+        dst[p+i] = src[i];
+    dst[p+i] = 0;
+    *pp = p+i;
+}
+*/
+
+SQInteger _ext_getfuncinfo(HSQUIRRELVM v){
+    SQObjectPtr &o = stack_get(v,2);
+    SQChar *stype, *stemp = sq_getscratchpad(v,200);
+    SQChar buf[16];
+    *stemp = 0;
+    //printf( "type: %08X\n", type(o) );
+
+    if( type(o)!=OT_NATIVECLOSURE && type(o)!=OT_CLOSURE && type(o)!=OT_FUNCPROTO )
+        return 0;
+
+    sq_newtable(v);
+
+    switch( type(o) ){
+        case OT_NATIVECLOSURE:{
+            SQNativeClosure *pnc = o._unVal.pNativeClosure;
+            bool var_arg = pnc->_nparamscheck<0 ? true : false;
+
+            sq_pushstring(v,_SC("type"),-1);
+            sq_pushstring(v,_SC("native"),-1);
+            sq_rawset(v,-3);
+
+            sq_pushstring(v,_SC("args"),-1);
+            sq_newarray(v,0);
+
+            // If we don't have a typemask, use number of paramaters
+            if( !pnc->_typecheck.size() ){
+                if( pnc->_nparamscheck ){
+                    for( int i=(var_arg?-1:1)*pnc->_nparamscheck; i>0; i-- ){
+                        sq_pushstring(v,_SC("unspec"),-1);
+                        sq_arrayappend(v,-2);
+                    }
+                    if( var_arg ){
+                        sq_pushstring(v,_SC("..."),-1);
+                        sq_arrayappend(v,-2);
+                    }
+                }
+                else{
+                    sq_pushstring(v,_SC("???"),-1);
+                    sq_arrayappend(v,-2);
+                }
+            }
+            else{
+                // Write type of each argument
+                SQObjectType type_val;
+                unsigned int i;
+                for( i=0; i<pnc->_typecheck.size(); i++ ){
+                    type_val = SQObjectType(pnc->_typecheck._vals[i]);
+                    if( type_val==-1 ) stype = _SC("any");
+                    else{
+                        stype = (SQChar*)IdType2Name( type_val );
+                        if( !stype ){
+                            if( (type_val&(_RT_FLOAT|_RT_INTEGER))==(_RT_FLOAT|_RT_INTEGER) )
+                                stype = _SC("number");
+                            else{
+                                scsprintf( buf, _SC("unknown<%X>"), type_val );
+                                stype = buf; // (SQChar*)(!i ? _SC("env") : _SC("unknown"));
+                            }
+                        }
+                    }
+                    sq_pushstring(v,stype,-1);
+                    sq_arrayappend(v,-2);
+                }
+                
+                // If typemask is too short, correct for that
+                for( unsigned int imax = (var_arg?-1:1)*pnc->_nparamscheck; i<imax; i++ ){
+                    sq_pushstring(v,_SC("unsp"),-1);
+                    sq_arrayappend(v,-2);
+                }
+                
+                if( var_arg ){
+                    sq_pushstring(v,_SC("..."),-1);
+                    sq_arrayappend(v,-2);
+                }
+            }
+            sq_rawset(v,-3);    // Slot the array into the table
+            break;
+        }
+
+        case OT_CLOSURE:
+        case OT_FUNCPROTO:{
+            SQFunctionProto *pfp;
+            if( type(o)==OT_CLOSURE ) pfp = _funcproto(o._unVal.pClosure->_function);
+            else pfp = o._unVal.pFunctionProto;
+
+            sq_pushstring(v,_SC("type"),-1);
+            sq_pushstring(v,_SC(type(o)==OT_CLOSURE?"closure":"proto"),-1);
+            sq_rawset(v,-3);
+
+            sq_pushstring(v,_SC("args"),-1);
+            sq_newarra
download for full patch...