浏览代码

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)
 .. 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)
 .. js:function:: strip(str)
 
 
@@ -162,13 +162,13 @@ The regexp class
 
 
 .. js:function:: regexp.capture(str [, start])
 .. 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`.
     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.
     An array entry is created for each captured sub expressions. If no match occurs returns null.
     The search starts from the index `start`
     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
     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`
     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
     searches the first match of the expression in the string delimited
     by the parameter text_begin and text_end.
     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.
     match and out_end at the end of the match; otherwise returns SQFalse.
 
 
 .. c:function:: SQInteger sqstd_rex_getsubexpcount(SQRex * exp)
 .. c:function:: SQInteger sqstd_rex_getsubexpcount(SQRex * exp)
@@ -305,7 +305,7 @@ Regular Expessions
     :param SQRex* exp: a compiled expression
     :param SQRex* exp: a compiled expression
     :param SQInteger n: the index of the submatch(0 is the complete match)
     :param SQInteger n: the index of the submatch(0 is the complete match)
     :param SQRexMatch* a: pointer to structure that will store the result
     :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
     retrieve the begin and and pointer to the length of the sub expression indexed
     by n. The result is passed through the struct SQRexMatch.
     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
 #define SQSTD_STREAM_TYPE_TAG 0x80000000
 
 
 struct SQStream {
 struct SQStream {
+    virtual ~SQStream() {}
     virtual SQInteger Read(void *buffer, SQInteger size) = 0;
     virtual SQInteger Read(void *buffer, SQInteger size) = 0;
     virtual SQInteger Write(void *buffer, SQInteger size) = 0;
     virtual SQInteger Write(void *buffer, SQInteger size) = 0;
     virtual SQInteger Flush() = 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)
 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))) {
     if(SQ_SUCCEEDED(sqstd_loadfile(v,filename,printerror))) {
         sq_push(v,-2);
         sq_push(v,-2);
         if(SQ_SUCCEEDED(sq_call(v,1,retval,SQTrue))) {
         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)
 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)
 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)
 void sq_setcompilererrorhandler(HSQUIRRELVM v,SQCOMPILERERROR f)