ソースを参照

Merge pull request #38 from zeromus/master

releasehook APIs and docs fixes
Alberto Demichelis 9 年 前
コミット
35ab252494
共有4 個のファイルを変更した24 個の追加24 個の削除を含む
  1. 7 7
      doc/source/stdlib/stdstringlib.rst
  2. 1 0
      include/sqstdio.h
  3. 4 0
      sqstdlib/sqstdio.cpp
  4. 12 17
      squirrel/sqapi.cpp

+ 7 - 7
doc/source/stdlib/stdstringlib.rst

@@ -57,7 +57,7 @@ Global Symbols
 
 .. js:function:: startswith(str, cmp)
 
-    returns `true` if the beginning of the string `str`  matches a the string `cmp` otherwise returns `false`
+    returns `true` if the beginning of the string `str` matches the string `cmp`; otherwise returns `false`
 	
 .. js:function:: strip(str)
 
@@ -162,13 +162,13 @@ The regexp class
 
 .. js:function:: regexp.capture(str [, start])
 
-    returns an array of tables containing two indexs("begin" and "end")of
+    returns an array of tables containing two indexes ("begin" and "end") of
     the first match of the regular expression in the string `str`.
     An array entry is created for each captured sub expressions. If no match occurs returns null.
     The search starts from the index `start`
-    of the string, if `start` is omitted the search starts from the beginning of the string.
+    of the string; if `start` is omitted the search starts from the beginning of the string.
 
-    the first element of the returned array(index 0) always contains the complete match.
+    The first element of the returned array(index 0) always contains the complete match.
 
     ::
 
@@ -197,7 +197,7 @@ The regexp class
 
     returns a table containing two indexes ("begin" and "end") of the first match of the regular expression in
     the string `str`, otherwise if no match occurs returns null. The search starts from the index `start`
-    of the string, if `start` is omitted the search starts from the beginning of the string.
+    of the string; if `start` is omitted the search starts from the beginning of the string.
 
     ::
 
@@ -290,7 +290,7 @@ Regular Expessions
 
     searches the first match of the expression in the string delimited
     by the parameter text_begin and text_end.
-    if the match is found returns SQTrue and the sets out_begin to the beginning of the
+    if the match is found returns SQTrue and sets out_begin to the beginning of the
     match and out_end at the end of the match; otherwise returns SQFalse.
 
 .. c:function:: SQInteger sqstd_rex_getsubexpcount(SQRex * exp)
@@ -305,7 +305,7 @@ Regular Expessions
     :param SQRex* exp: a compiled expression
     :param SQInteger n: the index of the submatch(0 is the complete match)
     :param SQRexMatch* a: pointer to structure that will store the result
-    :returns: the function returns SQTrue if n is valid index otherwise SQFalse.
+    :returns: the function returns SQTrue if n is a valid index; otherwise SQFalse.
 
     retrieve the begin and and pointer to the length of the sub expression indexed
     by n. The result is passed through the struct SQRexMatch.

+ 1 - 0
include/sqstdio.h

@@ -7,6 +7,7 @@
 #define SQSTD_STREAM_TYPE_TAG 0x80000000
 
 struct SQStream {
+    virtual ~SQStream() {}
     virtual SQInteger Read(void *buffer, SQInteger size) = 0;
     virtual SQInteger Write(void *buffer, SQInteger size) = 0;
     virtual SQInteger Flush() = 0;

+ 4 - 0
sqstdlib/sqstdio.cpp

@@ -399,6 +399,10 @@ SQRESULT sqstd_loadfile(HSQUIRRELVM v,const SQChar *filename,SQBool printerror)
 
 SQRESULT sqstd_dofile(HSQUIRRELVM v,const SQChar *filename,SQBool retval,SQBool printerror)
 {
+    //at least one entry must exist in order for us to push it as the environment
+    if(sq_gettop(v) == 0)
+        return sq_throwerror(v,_SC("environment table expected"));	
+
     if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,printerror))) {
         sq_push(v,-2);
         if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue))) {

+ 12 - 17
squirrel/sqapi.cpp

@@ -1199,29 +1199,24 @@ SQRESULT sq_wakeupvm(HSQUIRRELVM v,SQBool wakeupret,SQBool retval,SQBool raiseer
 
 void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK hook)
 {
-    if(sq_gettop(v) >= 1){
-        SQObjectPtr &ud=stack_get(v,idx);
-        switch( type(ud) ) {
-        case OT_USERDATA:   _userdata(ud)->_hook = hook;    break;
-        case OT_INSTANCE:   _instance(ud)->_hook = hook;    break;
-        case OT_CLASS:      _class(ud)->_hook = hook;       break;
-        default: break; //shutup compiler
-        }
+    SQObjectPtr &ud=stack_get(v,idx);
+    switch( type(ud) ) {
+    case OT_USERDATA:   _userdata(ud)->_hook = hook;    break;
+    case OT_INSTANCE:   _instance(ud)->_hook = hook;    break;
+    case OT_CLASS:      _class(ud)->_hook = hook;       break;
+    default: return;
     }
 }
 
 SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx)
 {
-    if(sq_gettop(v) >= 1){
-        SQObjectPtr &ud=stack_get(v,idx);
-        switch( type(ud) ) {
-        case OT_USERDATA:   return _userdata(ud)->_hook;    break;
-        case OT_INSTANCE:   return _instance(ud)->_hook;    break;
-        case OT_CLASS:      return _class(ud)->_hook;       break;
-        default: break; //shutup compiler
-        }
+    SQObjectPtr &ud=stack_get(v,idx);
+    switch( type(ud) ) {
+    case OT_USERDATA:   return _userdata(ud)->_hook;    break;
+    case OT_INSTANCE:   return _instance(ud)->_hook;    break;
+    case OT_CLASS:      return _class(ud)->_hook;       break;
+    default: return NULL;
     }
-    return NULL;
 }
 
 void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f)