Browse Source

Merge branch 'master' of https://github.com/albertodemichelis/squirrel

albertodemichelis 6 years ago
parent
commit
a1cbf6e5ab

+ 1 - 1
.gitignore

@@ -3,4 +3,4 @@ bin/
 lib/
 lib/
 
 
 # Folders created at documentation generation
 # Folders created at documentation generation
-doc/
+doc/build/

+ 11 - 6
CMakeLists.txt

@@ -4,8 +4,13 @@ else()
   cmake_minimum_required(VERSION 2.8)
   cmake_minimum_required(VERSION 2.8)
 endif()
 endif()
 
 
+option(DISABLE_STATIC "Avoid building/installing static libraries.")
+option(LONG_OUTPUT_NAMES "Use longer names for binaries and libraries: squirrel3 (not sq).")
+
 set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}" CACHE PATH "")
 set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}" CACHE PATH "")
-set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
+if (NOT CMAKE_BUILD_TYPE)
+  set(CMAKE_BUILD_TYPE "Release")
+endif ()
 
 
 project(squirrel C CXX)
 project(squirrel C CXX)
 
 
@@ -40,12 +45,12 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 8)
   add_definitions(-D_SQ64)
   add_definitions(-D_SQ64)
 endif()
 endif()
 
 
-if(NOT DEFINED SQ_DISABLE_INSTALLER)
-  if(NOT DEFINED INSTALL_BIN_DIR)
+if(NOT SQ_DISABLE_INSTALLER)
+  if(NOT INSTALL_BIN_DIR)
     set(INSTALL_BIN_DIR bin)
     set(INSTALL_BIN_DIR bin)
   endif()
   endif()
 
 
-  if(NOT DEFINED INSTALL_LIB_DIR)
+  if(NOT INSTALL_LIB_DIR)
     set(INSTALL_LIB_DIR lib)
     set(INSTALL_LIB_DIR lib)
   endif()
   endif()
 endif()
 endif()
@@ -54,11 +59,11 @@ add_subdirectory(squirrel)
 add_subdirectory(sqstdlib)
 add_subdirectory(sqstdlib)
 add_subdirectory(sq)
 add_subdirectory(sq)
 
 
-if(NOT WIN32 AND NOT DEFINED DISABLE_DYNAMIC)
+if(NOT WIN32 AND NOT DISABLE_DYNAMIC)
   set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0)
   set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0)
 endif()
 endif()
 
 
-if(DEFINED INSTALL_INC_DIR)
+if(INSTALL_INC_DIR)
   set(SQ_PUB_HEADERS include/sqconfig.h
   set(SQ_PUB_HEADERS include/sqconfig.h
                      include/sqstdaux.h
                      include/sqstdaux.h
                      include/sqstdblob.h
                      include/sqstdblob.h

+ 3 - 3
doc/source/reference/api/object_creation_and_handling.rst

@@ -66,12 +66,12 @@ pushes the value of a class or instance member using a member handle (see sq_get
 
 
 .. _sq_getclosureinfo:
 .. _sq_getclosureinfo:
 
 
-.. c:function:: SQRESULT sq_getclosureinfo(HSQUIRRELVM v, SQInteger idx, SQUnsignedInteger * nparams, SQUnsignedInteger * nfreevars)
+.. c:function:: SQRESULT sq_getclosureinfo(HSQUIRRELVM v, SQInteger idx, SQInteger * nparams, SQInteger * nfreevars)
 
 
     :param HSQUIRRELVM v: the target VM
     :param HSQUIRRELVM v: the target VM
     :param SQInteger idx: index of the target closure
     :param SQInteger idx: index of the target closure
-    :param SQUnsignedInteger * nparams: a pointer to an unsigned integer that will store the number of parameters
-    :param SQUnsignedInteger * nfreevars: a pointer to an unsigned integer that will store the number of free variables
+    :param SQInteger * nparams: a pointer to an integer that will store the number of parameters
+    :param SQInteger * nfreevars: a pointer to an integer that will store the number of free variables
     :returns: an SQRESULT
     :returns: an SQRESULT
 
 
 retrieves number of parameters and number of freevariables from a squirrel closure.
 retrieves number of parameters and number of freevariables from a squirrel closure.

+ 1 - 1
doc/source/reference/api/object_manipulation.rst

@@ -164,7 +164,7 @@ pops a key from the stack and delete the slot indexed by it from the table at po
     :param HSQUIRRELVM v: the target VM
     :param HSQUIRRELVM v: the target VM
     :param SQInteger idx: index of the target object in the stack
     :param SQInteger idx: index of the target object in the stack
     :returns: a SQRESULT
     :returns: a SQRESULT
-    :remarks: this call will invokes the delegation system like a normal dereference it only works on tables, arrays and userdata; if the function fails, nothing will be pushed in the stack.
+    :remarks: this call will invokes the delegation system like a normal dereference it only works on tables, arrays, classes, instances and userdata; if the function fails, nothing will be pushed in the stack.
 
 
 pops a key from the stack and performs a get operation on the object at the position idx in the stack; and pushes the result in the stack.
 pops a key from the stack and performs a get operation on the object at the position idx in the stack; and pushes the result in the stack.
 
 

+ 8 - 8
doc/source/reference/embedding/build_configuration.rst

@@ -13,19 +13,19 @@ Unicode
 .. index:: single: Unicode
 .. index:: single: Unicode
 
 
 By default Squirrel strings are plain 8-bits ASCII characters; however if the symbol
 By default Squirrel strings are plain 8-bits ASCII characters; however if the symbol
-'SQUNICODE' is defined the VM, compiler and API will use 16-bits characters (UCS2).
+'SQUNICODE' is defined the VM, compiler and API will use 16-bit characters (UCS2).
 
 
 .. _squirrel_64bits:
 .. _squirrel_64bits:
 
 
----------------------------------
-Squirrel on 64 bits architectures
----------------------------------
+--------------------------------
+Squirrel on 64-bit architectures
+--------------------------------
 
 
 .. index::
 .. index::
-    single: Squirrel on 64 bits architectures
+    single: Squirrel on 64-bit architectures
     single: 64 bits
     single: 64 bits
 
 
-Squirrel can be compiled on 64 bits architectures by defining '_SQ64' in the C++
+Squirrel can be compiled on 64-bit architectures by defining '_SQ64' in the C++
 preprocessor. This flag should be defined in any project that includes 'squirrel.h'.
 preprocessor. This flag should be defined in any project that includes 'squirrel.h'.
 
 
 .. _userdata_alignment:
 .. _userdata_alignment:
@@ -38,7 +38,7 @@ Userdata Alignment
 
 
 Both class instances and userdatas can have a buffer associated to them.
 Both class instances and userdatas can have a buffer associated to them.
 Squirrel specifies the alignment(in bytes) through the preprocessor defining 'SQ_ALIGNMENT'.
 Squirrel specifies the alignment(in bytes) through the preprocessor defining 'SQ_ALIGNMENT'.
-By default SQ_ALIGNMENT is defined as 4 for 32 bits builds and 8 for 64bits builds and builds that use 64bits floats.
+By default SQ_ALIGNMENT is defined as 4 for 32-bit builds and 8 for 64-bit builds and builds that use 64-bit floats.
 It is possible to override the value of SQ_ALIGNMENT respecting the following rules.
 It is possible to override the value of SQ_ALIGNMENT respecting the following rules.
 SQ_ALIGNMENT shall be less than or equal to SQ_MALLOC alignments, and it shall be power of 2.
 SQ_ALIGNMENT shall be less than or equal to SQ_MALLOC alignments, and it shall be power of 2.
 
 
@@ -53,7 +53,7 @@ Stand-alone VM without compiler
 
 
 .. index:: single: Stand-alone VM without compiler
 .. index:: single: Stand-alone VM without compiler
 
 
-Squirrel's VM can be compiled without it's compiler by defining 'NO_COMPILER' in the C++ preprocessor.
+Squirrel's VM can be compiled without its compiler by defining 'NO_COMPILER' in the C++ preprocessor.
 When 'NO_COMPILER' is defined all function related to the compiler (eg. sq_compile) will fail. Other functions
 When 'NO_COMPILER' is defined all function related to the compiler (eg. sq_compile) will fail. Other functions
 that conditionally load precompiled bytecode or compile a file (eg. sqstd_dofile) will only work with
 that conditionally load precompiled bytecode or compile a file (eg. sqstd_dofile) will only work with
 precompiled bytecode.
 precompiled bytecode.

+ 1 - 1
doc/source/reference/embedding/calling_a_function.rst

@@ -16,7 +16,7 @@ parameter is > 0. ::
     sq_pushinteger(v,1);
     sq_pushinteger(v,1);
     sq_pushfloat(v,2.0);
     sq_pushfloat(v,2.0);
     sq_pushstring(v,"three",-1);
     sq_pushstring(v,"three",-1);
-    sq_call(v,4,SQFalse);
+    sq_call(v,4,SQFalse,SQFalse);
     sq_pop(v,2); //pops the roottable and the function
     sq_pop(v,2); //pops the roottable and the function
 
 
 this is equivalent to the following Squirrel code::
 this is equivalent to the following Squirrel code::

+ 1 - 1
doc/source/reference/embedding/compiling_a_script.rst

@@ -8,7 +8,7 @@ You can compile a Squirrel script with the function *sq_compile*.::
 
 
     typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer userdata);
     typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer userdata);
 
 
-    SQRESULT sq_compile(HSQUIRRELVM v,SQREADFUNC read,SQUserPointer p,
+    SQRESULT sq_compile(HSQUIRRELVM v,SQLEXREADFUNC read,SQUserPointer p,
                 const SQChar *sourcename,SQBool raiseerror);
                 const SQChar *sourcename,SQBool raiseerror);
 
 
 In order to compile a script is necessary for the host application to implement a reader
 In order to compile a script is necessary for the host application to implement a reader

+ 2 - 1
doc/source/reference/embedding/creating_a_c_function.rst

@@ -99,7 +99,8 @@ Here an example of how to register a function::
     {
     {
         sq_pushroottable(v);
         sq_pushroottable(v);
         sq_pushstring(v,fname,-1);
         sq_pushstring(v,fname,-1);
-        sq_newclosure(v,f,0,0); //create a new function
+        sq_newclosure(v,f,0); //create a new function
         sq_newslot(v,-3,SQFalse);
         sq_newslot(v,-3,SQFalse);
         sq_pop(v,1); //pops the root table
         sq_pop(v,1); //pops the root table
+        return 0;
     }
     }

+ 2 - 2
doc/source/reference/embedding/references_from_c.rst

@@ -11,11 +11,11 @@ The object can be also re-pushed in the VM stack using sq_pushobject().::
 
 
     HSQOBJECT obj;
     HSQOBJECT obj;
 
 
-    sq_resetobject(v,&obj) //initialize the handle
+    sq_resetobject(&obj); //initialize the handle
     sq_getstackobj(v,-2,&obj); //retrieve an object handle from the pos -2
     sq_getstackobj(v,-2,&obj); //retrieve an object handle from the pos -2
     sq_addref(v,&obj); //adds a reference to the object
     sq_addref(v,&obj); //adds a reference to the object
 
 
     ... //do stuff
     ... //do stuff
 
 
-    sq_pushobject(v,&obj); //push the object in the stack
+    sq_pushobject(v,obj); //push the object in the stack
     sq_release(v,&obj); //relese the object
     sq_release(v,&obj); //relese the object

+ 34 - 17
doc/source/reference/language/builtin_functions.rst

@@ -53,9 +53,9 @@ returns the const table of the VM.
 
 
 sets the const table of the VM; returns the previous const table.
 sets the const table of the VM; returns the previous const table.
 
 
-.. js:function:: assert(exp)
+.. js:function:: assert(exp, [message])
 
 
-throws an exception if exp is null
+throws an exception if exp is null or false. Throws "assertion failed" string by default, or message if specified.
 
 
 .. js:function:: print(x)
 .. js:function:: print(x)
 
 
@@ -279,7 +279,7 @@ tries to get a value from the slot 'key' without employing delegation
 
 
 .. js:function:: table.rawset(key,val)
 .. js:function:: table.rawset(key,val)
 
 
-Sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists, it will be created.
+Sets the slot 'key' with the value 'val' without employing delegation. If the slot does not exists, it will be created. Returns table itself.
 
 
 
 
 .. js:function:: table.rawdelete()
 .. js:function:: table.rawdelete()
@@ -304,7 +304,7 @@ Tries to invoke the _tostring metamethod. If that fails, it returns "(table : po
 
 
 .. js:function:: table.clear()
 .. js:function:: table.clear()
 
 
-removes all the slots from the table
+removes all the slots from the table. Returns table itself.
 
 
 
 
 .. js:function:: table.setdelegate(table)
 .. js:function:: table.setdelegate(table)
@@ -316,6 +316,11 @@ Sets the delegate of the table. To remove a delegate, 'null' must be passed to t
 
 
 returns the table's delegate or null if no delegate was set.
 returns the table's delegate or null if no delegate was set.
 
 
+
+.. js:function:: table.filter(func(key,val))
+
+Creates a new table with all values that pass the test implemented by the provided function. In detail, it creates a new table, invokes the specified function for each key-value pair in the original table; if the function returns 'true', then the value is added to the newly created table at the same key.
+
 ^^^^^^
 ^^^^^^
 Array
 Array
 ^^^^^^
 ^^^^^^
@@ -327,17 +332,17 @@ returns the length of the array
 
 
 .. js:function:: array.append(val)
 .. js:function:: array.append(val)
 
 
-appends the value 'val' at the end of the array
+appends the value 'val' at the end of the array. Returns array itself.
 
 
 
 
 .. js:function:: array.push(val)
 .. js:function:: array.push(val)
 
 
-appends the value 'val' at the end of the array
+appends the value 'val' at the end of the array. Returns array itself.
 
 
 
 
 .. js:function:: array.extend(array)
 .. js:function:: array.extend(array)
 
 
-Extends the array by appending all the items in the given array.
+Extends the array by appending all the items in the given array. Returns array itself.
 
 
 
 
 .. js:function:: array.pop()
 .. js:function:: array.pop()
@@ -352,22 +357,22 @@ returns the value of the array with the higher index
 
 
 .. js:function:: array.insert(idx,val)
 .. js:function:: array.insert(idx,val)
 
 
-inserts the value 'val' at the position 'idx' in the array
+inserts the value 'val' at the position 'idx' in the array. Returns array itself.
 
 
 
 
 .. js:function:: array.remove(idx)
 .. js:function:: array.remove(idx)
 
 
-removes the value at the position 'idx' in the array
+removes the value at the position 'idx' in the array and returns its value.
 
 
 
 
 .. js:function:: array.resize(size,[fill])
 .. js:function:: array.resize(size,[fill])
 
 
-Resizes the array. If the optional parameter 'fill' is specified, its value will be used to fill the new array's slots when the size specified is bigger than the previous size. If the fill parameter is omitted, null is used instead.
+Resizes the array. If the optional parameter 'fill' is specified, its value will be used to fill the new array's slots when the size specified is bigger than the previous size. If the fill parameter is omitted, null is used instead. Returns array itself.
 
 
 
 
 .. js:function:: array.sort([compare_func])
 .. js:function:: array.sort([compare_func])
 
 
-Sorts the array. A custom compare function can be optionally passed. The function prototype as to be the following.::
+Sorts the array in-place. A custom compare function can be optionally passed. The function prototype as to be the following.::
 
 
     function custom_compare(a,b)
     function custom_compare(a,b)
     {
     {
@@ -380,11 +385,11 @@ a more compact version of a custom compare can be written using a lambda express
 
 
     arr.sort(@(a,b) a <=> b);
     arr.sort(@(a,b) a <=> b);
 
 
-
+Returns array itself.
 
 
 .. js:function:: array.reverse()
 .. js:function:: array.reverse()
 
 
-reverse the elements of the array in place
+reverse the elements of the array in place. Returns array itself.
 
 
 
 
 .. js:function:: array.slice(start,[end])
 .. js:function:: array.slice(start,[end])
@@ -407,19 +412,31 @@ returns the string "(array : pointer)".
 removes all the items from the array
 removes all the items from the array
 
 
 
 
-.. js:function:: array.map(func(a))
+.. js:function:: array.map(func(item_value, [item_index], [array_ref]))
 
 
 Creates a new array of the same size. For each element in the original array invokes the function 'func' and assigns the return value of the function to the corresponding element of the newly created array.
 Creates a new array of the same size. For each element in the original array invokes the function 'func' and assigns the return value of the function to the corresponding element of the newly created array.
+Provided func can accept up to 3 arguments: array item value (required), array item index (optional), reference to array itself (optional).
 
 
 
 
-.. js:function:: array.apply(func(a))
+.. js:function:: array.apply(func([item_value, [item_index], [array_ref]))
 
 
 for each element in the array invokes the function 'func' and replace the original value of the element with the return value of the function.
 for each element in the array invokes the function 'func' and replace the original value of the element with the return value of the function.
 
 
 
 
-.. js:function:: array.reduce(func(prevval,curval))
+.. js:function:: array.reduce(func(prevval,curval), [initializer])
+
+Reduces an array to a single value. For each element in the array invokes the function 'func' passing
+the initial value (or value from the previous callback call) and the value of the current element.
+The return value of the function is then used as 'prevval' for the next element.
+If the optional initializer is present, it is placed before the items of the array in the calculation,
+and serves as a default when the sequence is empty.
+If initializer is not given then for sequence contains only one item, reduce() returns the first item,
+and for empty sequence returns null.
 
 
-Reduces an array to a single value. For each element in the array invokes the function 'func' passing the initial value (or value from the previous callback call) and the value of the current element. the return value of the function is then used as 'prevval' for the next element. Given an array of length 0, returns null. Given an array of length 1, returns the first element. Given an array with 2 or more elements calls the function with the first two elements as the parameters, gets that result, then calls the function with that result and the third element, gets that result, calls the function with that result and the fourth parameter and so on until all element have been processed. Finally, returns the return value of the last invocation of func.
+Given an sequence with 2 or more elements (including initializer) calls the function with the first two elements as the parameters,
+gets that result, then calls the function with that result and the third element, gets that result,
+calls the function with that result and the fourth parameter and so on until all element have been processed.
+Finally, returns the return value of the last invocation of func.
 
 
 
 
 .. js:function:: array.filter(func(index,val))
 .. js:function:: array.filter(func(index,val))

+ 1 - 1
include/squirrel.h

@@ -276,7 +276,7 @@ SQUIRREL_API void sq_setreleasehook(HSQUIRRELVM v,SQInteger idx,SQRELEASEHOOK ho
 SQUIRREL_API SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx);
 SQUIRREL_API SQRELEASEHOOK sq_getreleasehook(HSQUIRRELVM v,SQInteger idx);
 SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
 SQUIRREL_API SQChar *sq_getscratchpad(HSQUIRRELVM v,SQInteger minsize);
 SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi);
 SQUIRREL_API SQRESULT sq_getfunctioninfo(HSQUIRRELVM v,SQInteger level,SQFunctionInfo *fi);
-SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars);
+SQUIRREL_API SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQInteger *nparams,SQInteger *nfreevars);
 SQUIRREL_API SQRESULT sq_getclosurename(HSQUIRRELVM v,SQInteger idx);
 SQUIRREL_API SQRESULT sq_getclosurename(HSQUIRRELVM v,SQInteger idx);
 SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
 SQUIRREL_API SQRESULT sq_setnativeclosurename(HSQUIRRELVM v,SQInteger idx,const SQChar *name);
 SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);
 SQUIRREL_API SQRESULT sq_setinstanceup(HSQUIRRELVM v, SQInteger idx, SQUserPointer p);

+ 8 - 8
sq/CMakeLists.txt

@@ -1,34 +1,34 @@
-if(NOT DEFINED DISABLE_DYNAMIC)
+if(NOT DISABLE_DYNAMIC)
   if(CMAKE_COMPILER_IS_GNUCXX)
   if(CMAKE_COMPILER_IS_GNUCXX)
     set_source_files_properties(sq.c PROPERTIES COMPILE_FLAGS -std=c99)
     set_source_files_properties(sq.c PROPERTIES COMPILE_FLAGS -std=c99)
   endif()
   endif()
   add_executable(sq sq.c)
   add_executable(sq sq.c)
   set_target_properties(sq PROPERTIES LINKER_LANGUAGE C)
   set_target_properties(sq PROPERTIES LINKER_LANGUAGE C)
   target_link_libraries(sq squirrel sqstdlib)
   target_link_libraries(sq squirrel sqstdlib)
-  if(NOT DEFINED SQ_DISABLE_INSTALLER)
+  if(NOT SQ_DISABLE_INSTALLER)
     install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR})
     install(TARGETS sq RUNTIME DESTINATION ${INSTALL_BIN_DIR})
   endif()
   endif()
 endif()
 endif()
 
 
-if(NOT DEFINED DISABLE_STATIC)
+if(NOT DISABLE_STATIC)
   add_executable(sq_static sq.c)
   add_executable(sq_static sq.c)
   set_target_properties(sq_static PROPERTIES LINKER_LANGUAGE C)
   set_target_properties(sq_static PROPERTIES LINKER_LANGUAGE C)
   target_link_libraries(sq_static squirrel_static sqstdlib_static)
   target_link_libraries(sq_static squirrel_static sqstdlib_static)
-  if(NOT DEFINED SQ_DISABLE_INSTALLER)
+  if(NOT SQ_DISABLE_INSTALLER)
     install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR})
     install(TARGETS sq_static RUNTIME DESTINATION ${INSTALL_BIN_DIR})
   endif()
   endif()
 endif()
 endif()
 
 
-if(DEFINED LONG_OUTPUT_NAMES)
-  if(NOT DEFINED DISABLE_DYNAMIC)
+if(LONG_OUTPUT_NAMES)
+  if(NOT DISABLE_DYNAMIC)
     set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3)
     set_target_properties(sq PROPERTIES OUTPUT_NAME squirrel3)
   endif()
   endif()
 
 
-  if(NOT DEFINED DISABLE_STATIC)
+  if(NOT DISABLE_STATIC)
     set_target_properties(sq_static PROPERTIES OUTPUT_NAME squirrel3_static)
     set_target_properties(sq_static PROPERTIES OUTPUT_NAME squirrel3_static)
   endif()
   endif()
 endif()
 endif()
 
 
-if(CMAKE_COMPILER_IS_GNUCXX AND (NOT DEFINED DISABLE_STATIC))
+if(CMAKE_COMPILER_IS_GNUCXX AND NOT DISABLE_STATIC)
   set_target_properties(sq_static PROPERTIES COMPILE_FLAGS "-static -Wl,-static")
   set_target_properties(sq_static PROPERTIES COMPILE_FLAGS "-static -Wl,-static")
 endif()
 endif()

+ 7 - 7
sqstdlib/CMakeLists.txt

@@ -7,29 +7,29 @@ set(SQSTDLIB_SRC sqstdaux.cpp
                  sqstdstring.cpp
                  sqstdstring.cpp
                  sqstdsystem.cpp)
                  sqstdsystem.cpp)
 
 
-if(NOT DEFINED DISABLE_DYNAMIC)
+if(NOT DISABLE_DYNAMIC)
   add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
   add_library(sqstdlib SHARED ${SQSTDLIB_SRC})
   target_link_libraries(sqstdlib squirrel)
   target_link_libraries(sqstdlib squirrel)
-  if(NOT DEFINED SQ_DISABLE_INSTALLER)
+  if(NOT SQ_DISABLE_INSTALLER)
     install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR}
     install(TARGETS sqstdlib RUNTIME DESTINATION ${INSTALL_BIN_DIR}
                              LIBRARY DESTINATION ${INSTALL_LIB_DIR}
                              LIBRARY DESTINATION ${INSTALL_LIB_DIR}
                              ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
                              ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
   endif()
   endif()
 endif()
 endif()
 
 
-if(NOT DEFINED DISABLE_STATIC)
+if(NOT DISABLE_STATIC)
   add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC})
   add_library(sqstdlib_static STATIC ${SQSTDLIB_SRC})
-  if(NOT DEFINED SQ_DISABLE_INSTALLER)
+  if(NOT SQ_DISABLE_INSTALLER)
     install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
     install(TARGETS sqstdlib_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
   endif()
   endif()
 endif()
 endif()
 
 
-if(DEFINED LONG_OUTPUT_NAMES)
-  if(NOT DEFINED DISABLE_DYNAMIC)
+if(LONG_OUTPUT_NAMES)
+  if(NOT DISABLE_DYNAMIC)
     set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
     set_target_properties(sqstdlib PROPERTIES OUTPUT_NAME sqstdlib3)
   endif()
   endif()
 
 
-  if(NOT DEFINED DISABLE_STATIC)
+  if(NOT DISABLE_STATIC)
     set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static)
     set_target_properties(sqstdlib_static PROPERTIES OUTPUT_NAME sqstdlib3_static)
   endif()
   endif()
 endif()
 endif()

+ 4 - 3
sqstdlib/Makefile

@@ -1,6 +1,7 @@
 SQUIRREL= ..
 SQUIRREL= ..
 
 
 
 
+CC?= gcc
 OUT?= $(SQUIRREL)/lib/libsqstdlib.a
 OUT?= $(SQUIRREL)/lib/libsqstdlib.a
 INCZ?= -I$(SQUIRREL)/include -I. -Iinclude
 INCZ?= -I$(SQUIRREL)/include -I. -Iinclude
 DEFS= $(CC_EXTRA_FLAGS)
 DEFS= $(CC_EXTRA_FLAGS)
@@ -28,16 +29,16 @@ SRCS= \
 
 
 
 
 sq32:
 sq32:
-	gcc -O2 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
+	$(CC) -O2 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
 	ar rc $(OUT) *.o
 	ar rc $(OUT) *.o
 	rm *.o
 	rm *.o
 
 
 sqprof:
 sqprof:
-	gcc -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
+	$(CC) -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
 	ar rc $(OUT) *.o
 	ar rc $(OUT) *.o
 	rm *.o
 	rm *.o
 
 
 sq64:
 sq64:
-	gcc -O2 -m64 -fno-exceptions -D_SQ64 -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
+	$(CC) -O2 -m64 -fno-exceptions -D_SQ64 -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
 	ar rc $(OUT) *.o
 	ar rc $(OUT) *.o
 	rm *.o
 	rm *.o

+ 7 - 7
squirrel/CMakeLists.txt

@@ -11,28 +11,28 @@ set(SQUIRREL_SRC sqapi.cpp
                  sqtable.cpp
                  sqtable.cpp
                  sqvm.cpp)
                  sqvm.cpp)
 
 
-if(NOT DEFINED DISABLE_DYNAMIC)
+if(NOT DISABLE_DYNAMIC)
   add_library(squirrel SHARED ${SQUIRREL_SRC})
   add_library(squirrel SHARED ${SQUIRREL_SRC})
-  if(NOT DEFINED SQ_DISABLE_INSTALLER)
+  if(NOT SQ_DISABLE_INSTALLER)
     install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR}
     install(TARGETS squirrel RUNTIME DESTINATION ${INSTALL_BIN_DIR}
                          LIBRARY DESTINATION ${INSTALL_LIB_DIR}
                          LIBRARY DESTINATION ${INSTALL_LIB_DIR}
                          ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
                          ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
   endif()
   endif()
 endif()
 endif()
 
 
-if(NOT DEFINED DISABLE_STATIC)
+if(NOT DISABLE_STATIC)
   add_library(squirrel_static STATIC ${SQUIRREL_SRC})
   add_library(squirrel_static STATIC ${SQUIRREL_SRC})
-  if(NOT DEFINED SQ_DISABLE_INSTALLER)
+  if(NOT SQ_DISABLE_INSTALLER)
     install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
     install(TARGETS squirrel_static ARCHIVE DESTINATION ${INSTALL_LIB_DIR})
   endif()
   endif()
 endif()
 endif()
 
 
-if(DEFINED LONG_OUTPUT_NAMES)
-  if(NOT DEFINED DISABLE_DYNAMIC)
+if(LONG_OUTPUT_NAMES)
+  if(NOT DISABLE_DYNAMIC)
     set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
     set_target_properties(squirrel PROPERTIES OUTPUT_NAME squirrel3)
   endif()
   endif()
 
 
-  if(NOT DEFINED DISABLE_STATIC)
+  if(NOT DISABLE_STATIC)
     set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static)
     set_target_properties(squirrel_static PROPERTIES OUTPUT_NAME squirrel3_static)
   endif()
   endif()
 endif()
 endif()

+ 4 - 3
squirrel/Makefile

@@ -1,6 +1,7 @@
 SQUIRREL= ..
 SQUIRREL= ..
 
 
 
 
+CC?= gcc
 OUT?= $(SQUIRREL)/lib/libsquirrel.a
 OUT?= $(SQUIRREL)/lib/libsquirrel.a
 INCZ?= -I$(SQUIRREL)/include -I. -Iinclude
 INCZ?= -I$(SQUIRREL)/include -I. -Iinclude
 DEFS= $(CC_EXTRA_FLAGS)
 DEFS= $(CC_EXTRA_FLAGS)
@@ -37,16 +38,16 @@ SRCS= \
 
 
 
 
 sq32:
 sq32:
-	gcc -O2 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
+	$(CC) -O2 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
 	ar rc $(OUT) *.o
 	ar rc $(OUT) *.o
 	rm *.o
 	rm *.o
 
 
 sqprof:
 sqprof:
-	gcc -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
+	$(CC) -O2 -pg -fno-exceptions -fno-rtti -pie -gstabs -g3 -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
 	ar rc $(OUT) *.o
 	ar rc $(OUT) *.o
 	rm *.o
 	rm *.o
 
 
 sq64:
 sq64:
-	gcc -O2 -m64 -D_SQ64 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
+	$(CC) -O2 -m64 -D_SQ64 -fno-exceptions -fno-rtti -Wall -fno-strict-aliasing -c $(SRCS) $(INCZ) $(DEFS)
 	ar rc $(OUT) *.o
 	ar rc $(OUT) *.o
 	rm *.o
 	rm *.o

+ 11 - 19
squirrel/sqapi.cpp

@@ -394,21 +394,21 @@ void sq_newclosure(HSQUIRRELVM v,SQFUNCTION func,SQUnsignedInteger nfreevars)
     v->Push(SQObjectPtr(nc));
     v->Push(SQObjectPtr(nc));
 }
 }
 
 
-SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQUnsignedInteger *nparams,SQUnsignedInteger *nfreevars)
+SQRESULT sq_getclosureinfo(HSQUIRRELVM v,SQInteger idx,SQInteger *nparams,SQInteger *nfreevars)
 {
 {
     SQObject o = stack_get(v, idx);
     SQObject o = stack_get(v, idx);
     if(sq_type(o) == OT_CLOSURE) {
     if(sq_type(o) == OT_CLOSURE) {
         SQClosure *c = _closure(o);
         SQClosure *c = _closure(o);
         SQFunctionProto *proto = c->_function;
         SQFunctionProto *proto = c->_function;
-        *nparams = (SQUnsignedInteger)proto->_nparameters;
-        *nfreevars = (SQUnsignedInteger)proto->_noutervalues;
+        *nparams = proto->_nparameters;
+        *nfreevars = proto->_noutervalues;
         return SQ_OK;
         return SQ_OK;
     }
     }
     else if(sq_type(o) == OT_NATIVECLOSURE)
     else if(sq_type(o) == OT_NATIVECLOSURE)
     {
     {
         SQNativeClosure *c = _nativeclosure(o);
         SQNativeClosure *c = _nativeclosure(o);
-        *nparams = (SQUnsignedInteger)c->_nparamscheck;
-        *nfreevars = c->_noutervalues;
+        *nparams = c->_nparamscheck;
+        *nfreevars = (SQInteger)c->_noutervalues;
         return SQ_OK;
         return SQ_OK;
     }
     }
     return sq_throwerror(v,_SC("the object is not a closure"));
     return sq_throwerror(v,_SC("the object is not a closure"));
@@ -1175,23 +1175,15 @@ SQRESULT sq_resume(HSQUIRRELVM v,SQBool retval,SQBool raiseerror)
 SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
 SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
 {
 {
     SQObjectPtr res;
     SQObjectPtr res;
-    if(v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){
-
-        if(!v->_suspended) {
-            v->Pop(params);//pop args
-        }
-        if(retval){
-            v->Push(res); return SQ_OK;
-        }
-        return SQ_OK;
-    }
-    else {
-        v->Pop(params);
+    if(!v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){
+        v->Pop(params); //pop args
         return SQ_ERROR;
         return SQ_ERROR;
     }
     }
     if(!v->_suspended)
     if(!v->_suspended)
-        v->Pop(params);
-    return sq_throwerror(v,_SC("call failed"));
+        v->Pop(params); //pop args
+    if(retval)
+        v->Push(res); // push result
+    return SQ_OK;
 }
 }
 
 
 SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)
 SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)

+ 92 - 19
squirrel/sqbaselib.cpp

@@ -156,7 +156,14 @@ static SQInteger base_getstackinfos(HSQUIRRELVM v)
 static SQInteger base_assert(HSQUIRRELVM v)
 static SQInteger base_assert(HSQUIRRELVM v)
 {
 {
     if(SQVM::IsFalse(stack_get(v,2))){
     if(SQVM::IsFalse(stack_get(v,2))){
-        return sq_throwerror(v,_SC("assertion failed"));
+        SQInteger top = sq_gettop(v);
+        if (top>2 && SQ_SUCCEEDED(sq_tostring(v,3))) {
+            const SQChar *str = 0;
+            if (SQ_SUCCEEDED(sq_getstring(v,-1,&str))) {
+                return sq_throwerror(v, str);
+            }
+        }
+        return sq_throwerror(v, _SC("assertion failed"));
     }
     }
     return 0;
     return 0;
 }
 }
@@ -283,7 +290,7 @@ static const SQRegFunction base_funcs[]={
     {_SC("setroottable"),base_setroottable,2, NULL},
     {_SC("setroottable"),base_setroottable,2, NULL},
     {_SC("getconsttable"),base_getconsttable,1, NULL},
     {_SC("getconsttable"),base_getconsttable,1, NULL},
     {_SC("setconsttable"),base_setconsttable,2, NULL},
     {_SC("setconsttable"),base_setconsttable,2, NULL},
-    {_SC("assert"),base_assert,2, NULL},
+    {_SC("assert"),base_assert,-2, NULL},
     {_SC("print"),base_print,2, NULL},
     {_SC("print"),base_print,2, NULL},
     {_SC("error"),base_error,2, NULL},
     {_SC("error"),base_error,2, NULL},
     {_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
     {_SC("compilestring"),base_compilestring,-2, _SC(".ss")},
@@ -406,7 +413,7 @@ static SQInteger obj_delegate_weakref(HSQUIRRELVM v)
 
 
 static SQInteger obj_clear(HSQUIRRELVM v)
 static SQInteger obj_clear(HSQUIRRELVM v)
 {
 {
-    return sq_clear(v,-1);
+    return SQ_SUCCEEDED(sq_clear(v,-1)) ? 1 : SQ_ERROR;
 }
 }
 
 
 
 
@@ -443,7 +450,7 @@ static SQInteger container_rawexists(HSQUIRRELVM v)
 
 
 static SQInteger container_rawset(HSQUIRRELVM v)
 static SQInteger container_rawset(HSQUIRRELVM v)
 {
 {
-    return sq_rawset(v,-3);
+    return SQ_SUCCEEDED(sq_rawset(v,-3)) ? 1 : SQ_ERROR;
 }
 }
 
 
 
 
@@ -465,6 +472,34 @@ static SQInteger table_getdelegate(HSQUIRRELVM v)
     return SQ_SUCCEEDED(sq_getdelegate(v,-1))?1:SQ_ERROR;
     return SQ_SUCCEEDED(sq_getdelegate(v,-1))?1:SQ_ERROR;
 }
 }
 
 
+static SQInteger table_filter(HSQUIRRELVM v)
+{
+    SQObject &o = stack_get(v,1);
+    SQTable *tbl = _table(o);
+    SQObjectPtr ret = SQTable::Create(_ss(v),0);
+
+    SQObjectPtr itr, key, val;
+    SQInteger nitr;
+    while((nitr = tbl->Next(false, itr, key, val)) != -1) {
+        itr = (SQInteger)nitr;
+
+        v->Push(o);
+        v->Push(key);
+        v->Push(val);
+        if(SQ_FAILED(sq_call(v,3,SQTrue,SQFalse))) {
+            return SQ_ERROR;
+        }
+        if(!SQVM::IsFalse(v->GetUp(-1))) {
+            _table(ret)->NewSlot(key, val);
+        }
+        v->Pop();
+    }
+
+    v->Push(ret);
+    return 1;
+}
+
+
 const SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
 const SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
     {_SC("len"),default_delegate_len,1, _SC("t")},
     {_SC("len"),default_delegate_len,1, _SC("t")},
     {_SC("rawget"),container_rawget,2, _SC("t")},
     {_SC("rawget"),container_rawget,2, _SC("t")},
@@ -476,6 +511,7 @@ const SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
     {_SC("clear"),obj_clear,1, _SC(".")},
     {_SC("clear"),obj_clear,1, _SC(".")},
     {_SC("setdelegate"),table_setdelegate,2, _SC(".t|o")},
     {_SC("setdelegate"),table_setdelegate,2, _SC(".t|o")},
     {_SC("getdelegate"),table_getdelegate,1, _SC(".")},
     {_SC("getdelegate"),table_getdelegate,1, _SC(".")},
+    {_SC("filter"),table_filter,2, _SC("tc")},
     {NULL,(SQFUNCTION)0,0,NULL}
     {NULL,(SQFUNCTION)0,0,NULL}
 };
 };
 
 
@@ -483,18 +519,19 @@ const SQRegFunction SQSharedState::_table_default_delegate_funcz[]={
 
 
 static SQInteger array_append(HSQUIRRELVM v)
 static SQInteger array_append(HSQUIRRELVM v)
 {
 {
-    return sq_arrayappend(v,-2);
+    return SQ_SUCCEEDED(sq_arrayappend(v,-2)) ? 1 : SQ_ERROR;
 }
 }
 
 
 static SQInteger array_extend(HSQUIRRELVM v)
 static SQInteger array_extend(HSQUIRRELVM v)
 {
 {
     _array(stack_get(v,1))->Extend(_array(stack_get(v,2)));
     _array(stack_get(v,1))->Extend(_array(stack_get(v,2)));
-    return 0;
+    sq_pop(v,1);
+    return 1;
 }
 }
 
 
 static SQInteger array_reverse(HSQUIRRELVM v)
 static SQInteger array_reverse(HSQUIRRELVM v)
 {
 {
-    return sq_arrayreverse(v,-1);
+    return SQ_SUCCEEDED(sq_arrayreverse(v,-1)) ? 1 : SQ_ERROR;
 }
 }
 
 
 static SQInteger array_pop(HSQUIRRELVM v)
 static SQInteger array_pop(HSQUIRRELVM v)
@@ -519,7 +556,8 @@ static SQInteger array_insert(HSQUIRRELVM v)
     SQObject &val=stack_get(v,3);
     SQObject &val=stack_get(v,3);
     if(!_array(o)->Insert(tointeger(idx),val))
     if(!_array(o)->Insert(tointeger(idx),val))
         return sq_throwerror(v,_SC("index out of range"));
         return sq_throwerror(v,_SC("index out of range"));
-    return 0;
+    sq_pop(v,2);
+    return 1;
 }
 }
 
 
 static SQInteger array_remove(HSQUIRRELVM v)
 static SQInteger array_remove(HSQUIRRELVM v)
@@ -542,10 +580,15 @@ static SQInteger array_resize(HSQUIRRELVM v)
     SQObject &nsize = stack_get(v, 2);
     SQObject &nsize = stack_get(v, 2);
     SQObjectPtr fill;
     SQObjectPtr fill;
     if(sq_isnumeric(nsize)) {
     if(sq_isnumeric(nsize)) {
+        SQInteger sz = tointeger(nsize);
+        if (sz<0)
+          return sq_throwerror(v, _SC("resizing to negative length"));
+
         if(sq_gettop(v) > 2)
         if(sq_gettop(v) > 2)
             fill = stack_get(v, 3);
             fill = stack_get(v, 3);
-        _array(o)->Resize(tointeger(nsize),fill);
-        return 0;
+        _array(o)->Resize(sz,fill);
+        sq_settop(v, 1);
+        return 1;
     }
     }
     return sq_throwerror(v, _SC("size must be a number"));
     return sq_throwerror(v, _SC("size must be a number"));
 }
 }
@@ -553,16 +596,36 @@ static SQInteger array_resize(HSQUIRRELVM v)
 static SQInteger __map_array(SQArray *dest,SQArray *src,HSQUIRRELVM v) {
 static SQInteger __map_array(SQArray *dest,SQArray *src,HSQUIRRELVM v) {
     SQObjectPtr temp;
     SQObjectPtr temp;
     SQInteger size = src->Size();
     SQInteger size = src->Size();
+    SQObject &closure = stack_get(v, 2);
+    v->Push(closure);
+
+    SQInteger nArgs;
+    if(sq_type(closure) == OT_CLOSURE) {
+        nArgs = _closure(closure)->_function->_nparameters;
+    }
+    else if (sq_type(closure) == OT_NATIVECLOSURE) {
+        SQInteger nParamsCheck = _nativeclosure(closure)->_nparamscheck;
+        if (nParamsCheck > 0)
+            nArgs = nParamsCheck;
+        else // push all params when there is no check or only minimal count set
+            nArgs = 4;
+    }
+
     for(SQInteger n = 0; n < size; n++) {
     for(SQInteger n = 0; n < size; n++) {
         src->Get(n,temp);
         src->Get(n,temp);
         v->Push(src);
         v->Push(src);
         v->Push(temp);
         v->Push(temp);
-        if(SQ_FAILED(sq_call(v,2,SQTrue,SQFalse))) {
+        if (nArgs >= 3)
+            v->Push(SQObjectPtr(n));
+        if (nArgs >= 4)
+            v->Push(src);
+        if(SQ_FAILED(sq_call(v,nArgs,SQTrue,SQFalse))) {
             return SQ_ERROR;
             return SQ_ERROR;
         }
         }
         dest->Set(n,v->GetUp(-1));
         dest->Set(n,v->GetUp(-1));
         v->Pop();
         v->Pop();
     }
     }
+    v->Pop();
     return 0;
     return 0;
 }
 }
 
 
@@ -582,7 +645,8 @@ static SQInteger array_apply(HSQUIRRELVM v)
     SQObject &o = stack_get(v,1);
     SQObject &o = stack_get(v,1);
     if(SQ_FAILED(__map_array(_array(o),_array(o),v)))
     if(SQ_FAILED(__map_array(_array(o),_array(o),v)))
         return SQ_ERROR;
         return SQ_ERROR;
-    return 0;
+    sq_pop(v,1);
+    return 1;
 }
 }
 
 
 static SQInteger array_reduce(HSQUIRRELVM v)
 static SQInteger array_reduce(HSQUIRRELVM v)
@@ -590,14 +654,21 @@ static SQInteger array_reduce(HSQUIRRELVM v)
     SQObject &o = stack_get(v,1);
     SQObject &o = stack_get(v,1);
     SQArray *a = _array(o);
     SQArray *a = _array(o);
     SQInteger size = a->Size();
     SQInteger size = a->Size();
-    if(size == 0) {
+    SQObjectPtr res;
+    SQInteger iterStart;
+    if (sq_gettop(v)>2) {
+        res = stack_get(v,3);
+        iterStart = 0;
+    } else if (size==0) {
         return 0;
         return 0;
+    } else {
+        a->Get(0,res);
+        iterStart = 1;
     }
     }
-    SQObjectPtr res;
-    a->Get(0,res);
-    if(size > 1) {
+    if (size > iterStart) {
         SQObjectPtr other;
         SQObjectPtr other;
-        for(SQInteger n = 1; n < size; n++) {
+        v->Push(stack_get(v,2));
+        for (SQInteger n = iterStart; n < size; n++) {
             a->Get(n,other);
             a->Get(n,other);
             v->Push(o);
             v->Push(o);
             v->Push(res);
             v->Push(res);
@@ -608,6 +679,7 @@ static SQInteger array_reduce(HSQUIRRELVM v)
             res = v->GetUp(-1);
             res = v->GetUp(-1);
             v->Pop();
             v->Pop();
         }
         }
+        v->Pop();
     }
     }
     v->Push(res);
     v->Push(res);
     return 1;
     return 1;
@@ -749,7 +821,8 @@ static SQInteger array_sort(HSQUIRRELVM v)
             return SQ_ERROR;
             return SQ_ERROR;
 
 
     }
     }
-    return 0;
+    sq_settop(v,1);
+    return 1;
 }
 }
 
 
 static SQInteger array_slice(HSQUIRRELVM v)
 static SQInteger array_slice(HSQUIRRELVM v)
@@ -792,7 +865,7 @@ const SQRegFunction SQSharedState::_array_default_delegate_funcz[]={
     {_SC("clear"),obj_clear,1, _SC(".")},
     {_SC("clear"),obj_clear,1, _SC(".")},
     {_SC("map"),array_map,2, _SC("ac")},
     {_SC("map"),array_map,2, _SC("ac")},
     {_SC("apply"),array_apply,2, _SC("ac")},
     {_SC("apply"),array_apply,2, _SC("ac")},
-    {_SC("reduce"),array_reduce,2, _SC("ac")},
+    {_SC("reduce"),array_reduce,-2, _SC("ac.")},
     {_SC("filter"),array_filter,2, _SC("ac")},
     {_SC("filter"),array_filter,2, _SC("ac")},
     {_SC("find"),array_find,2, _SC("a.")},
     {_SC("find"),array_find,2, _SC("a.")},
     {NULL,(SQFUNCTION)0,0,NULL}
     {NULL,(SQFUNCTION)0,0,NULL}

+ 20 - 20
squirrel/sqcompiler.cpp

@@ -443,8 +443,8 @@ public:
             Expression();
             Expression();
             SQInteger second_exp = _fs->PopTarget();
             SQInteger second_exp = _fs->PopTarget();
             if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
             if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
-            _fs->SetIntructionParam(jmppos, 1, _fs->GetCurrentPos() - jmppos);
-            _fs->SetIntructionParam(jzpos, 1, endfirstexp - jzpos + 1);
+            _fs->SetInstructionParam(jmppos, 1, _fs->GetCurrentPos() - jmppos);
+            _fs->SetInstructionParam(jzpos, 1, endfirstexp - jzpos + 1);
             _fs->SnoozeOpt();
             _fs->SnoozeOpt();
             }
             }
             break;
             break;
@@ -482,7 +482,7 @@ public:
             SQInteger second_exp = _fs->PopTarget();
             SQInteger second_exp = _fs->PopTarget();
             if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
             if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
             _fs->SnoozeOpt();
             _fs->SnoozeOpt();
-            _fs->SetIntructionParam(jpos, 1, (_fs->GetCurrentPos() - jpos));
+            _fs->SetInstructionParam(jpos, 1, (_fs->GetCurrentPos() - jpos));
             _es.etype = EXPR;
             _es.etype = EXPR;
             break;
             break;
         }else return;
         }else return;
@@ -502,7 +502,7 @@ public:
             SQInteger second_exp = _fs->PopTarget();
             SQInteger second_exp = _fs->PopTarget();
             if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
             if(trg != second_exp) _fs->AddInstruction(_OP_MOVE, trg, second_exp);
             _fs->SnoozeOpt();
             _fs->SnoozeOpt();
-            _fs->SetIntructionParam(jpos, 1, (_fs->GetCurrentPos() - jpos));
+            _fs->SetInstructionParam(jpos, 1, (_fs->GetCurrentPos() - jpos));
             _es.etype = EXPR;
             _es.etype = EXPR;
             break;
             break;
             }
             }
@@ -834,7 +834,7 @@ public:
                     _fs->AddInstruction(_OP_APPENDARRAY, array, val, AAT_STACK);
                     _fs->AddInstruction(_OP_APPENDARRAY, array, val, AAT_STACK);
                     key++;
                     key++;
                 }
                 }
-                _fs->SetIntructionParam(apos, 1, key);
+                _fs->SetInstructionParam(apos, 1, key);
                 Lex();
                 Lex();
             }
             }
             break;
             break;
@@ -1002,7 +1002,7 @@ public:
             }
             }
         }
         }
         if(separator == _SC(',')) //hack recognizes a table from the separator
         if(separator == _SC(',')) //hack recognizes a table from the separator
-            _fs->SetIntructionParam(tpos, 1, nkeys);
+            _fs->SetInstructionParam(tpos, 1, nkeys);
         Lex();
         Lex();
     }
     }
     void LocalDeclStatement()
     void LocalDeclStatement()
@@ -1092,9 +1092,9 @@ public:
             //Statement(); if(_lex._prevtoken != _SC('}')) OptionalSemicolon();
             //Statement(); if(_lex._prevtoken != _SC('}')) OptionalSemicolon();
             IfBlock();
             IfBlock();
             //END_SCOPE();
             //END_SCOPE();
-            _fs->SetIntructionParam(jmppos, 1, _fs->GetCurrentPos() - jmppos);
+            _fs->SetInstructionParam(jmppos, 1, _fs->GetCurrentPos() - jmppos);
         }
         }
-        _fs->SetIntructionParam(jnepos, 1, endifblock - jnepos + (haselse?1:0));
+        _fs->SetInstructionParam(jnepos, 1, endifblock - jnepos + (haselse?1:0));
     }
     }
     void WhileStatement()
     void WhileStatement()
     {
     {
@@ -1111,7 +1111,7 @@ public:
 
 
         END_SCOPE();
         END_SCOPE();
         _fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1);
         _fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1);
-        _fs->SetIntructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
+        _fs->SetInstructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
 
 
         END_BREAKBLE_BLOCK(jmppos);
         END_BREAKBLE_BLOCK(jmppos);
     }
     }
@@ -1170,7 +1170,7 @@ public:
                 _fs->AddInstruction(exp[i]);
                 _fs->AddInstruction(exp[i]);
         }
         }
         _fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1, 0);
         _fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1, 0);
-        if(jzpos>  0) _fs->SetIntructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
+        if(jzpos>  0) _fs->SetInstructionParam(jzpos, 1, _fs->GetCurrentPos() - jzpos);
         
         
         END_BREAKBLE_BLOCK(continuetrg);
         END_BREAKBLE_BLOCK(continuetrg);
 
 
@@ -1211,8 +1211,8 @@ public:
         BEGIN_BREAKBLE_BLOCK()
         BEGIN_BREAKBLE_BLOCK()
         Statement();
         Statement();
         _fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1);
         _fs->AddInstruction(_OP_JMP, 0, jmppos - _fs->GetCurrentPos() - 1);
-        _fs->SetIntructionParam(foreachpos, 1, _fs->GetCurrentPos() - foreachpos);
-        _fs->SetIntructionParam(foreachpos + 1, 1, _fs->GetCurrentPos() - foreachpos);
+        _fs->SetInstructionParam(foreachpos, 1, _fs->GetCurrentPos() - foreachpos);
+        _fs->SetInstructionParam(foreachpos + 1, 1, _fs->GetCurrentPos() - foreachpos);
         END_BREAKBLE_BLOCK(foreachpos - 1);
         END_BREAKBLE_BLOCK(foreachpos - 1);
         //restore the local variable stack(remove index,val and ref idx)
         //restore the local variable stack(remove index,val and ref idx)
         _fs->PopTarget();
         _fs->PopTarget();
@@ -1232,7 +1232,7 @@ public:
             if(!bfirst) {
             if(!bfirst) {
                 _fs->AddInstruction(_OP_JMP, 0, 0);
                 _fs->AddInstruction(_OP_JMP, 0, 0);
                 skipcondjmp = _fs->GetCurrentPos();
                 skipcondjmp = _fs->GetCurrentPos();
-                _fs->SetIntructionParam(tonextcondjmp, 1, _fs->GetCurrentPos() - tonextcondjmp);
+                _fs->SetInstructionParam(tonextcondjmp, 1, _fs->GetCurrentPos() - tonextcondjmp);
             }
             }
             //condition
             //condition
             Lex(); Expression(); Expect(_SC(':'));
             Lex(); Expression(); Expect(_SC(':'));
@@ -1250,7 +1250,7 @@ public:
 
 
             //end condition
             //end condition
             if(skipcondjmp != -1) {
             if(skipcondjmp != -1) {
-                _fs->SetIntructionParam(skipcondjmp, 1, (_fs->GetCurrentPos() - skipcondjmp));
+                _fs->SetInstructionParam(skipcondjmp, 1, (_fs->GetCurrentPos() - skipcondjmp));
             }
             }
             tonextcondjmp = _fs->GetCurrentPos();
             tonextcondjmp = _fs->GetCurrentPos();
             BEGIN_SCOPE();
             BEGIN_SCOPE();
@@ -1259,7 +1259,7 @@ public:
             bfirst = false;
             bfirst = false;
         }
         }
         if(tonextcondjmp != -1)
         if(tonextcondjmp != -1)
-            _fs->SetIntructionParam(tonextcondjmp, 1, _fs->GetCurrentPos() - tonextcondjmp);
+            _fs->SetInstructionParam(tonextcondjmp, 1, _fs->GetCurrentPos() - tonextcondjmp);
         if(_token == TK_DEFAULT) {
         if(_token == TK_DEFAULT) {
             Lex(); Expect(_SC(':'));
             Lex(); Expect(_SC(':'));
             BEGIN_SCOPE();
             BEGIN_SCOPE();
@@ -1403,14 +1403,14 @@ public:
         if(_fs->_continuetargets.size()) _fs->_continuetargets.top()--;
         if(_fs->_continuetargets.size()) _fs->_continuetargets.top()--;
         _fs->AddInstruction(_OP_JMP, 0, 0);
         _fs->AddInstruction(_OP_JMP, 0, 0);
         SQInteger jmppos = _fs->GetCurrentPos();
         SQInteger jmppos = _fs->GetCurrentPos();
-        _fs->SetIntructionParam(trappos, 1, (_fs->GetCurrentPos() - trappos));
+        _fs->SetInstructionParam(trappos, 1, (_fs->GetCurrentPos() - trappos));
         Expect(TK_CATCH); Expect(_SC('(')); exid = Expect(TK_IDENTIFIER); Expect(_SC(')'));
         Expect(TK_CATCH); Expect(_SC('(')); exid = Expect(TK_IDENTIFIER); Expect(_SC(')'));
         {
         {
             BEGIN_SCOPE();
             BEGIN_SCOPE();
             SQInteger ex_target = _fs->PushLocalVariable(exid);
             SQInteger ex_target = _fs->PushLocalVariable(exid);
-            _fs->SetIntructionParam(trappos, 0, ex_target);
+            _fs->SetInstructionParam(trappos, 0, ex_target);
             Statement();
             Statement();
-            _fs->SetIntructionParams(jmppos, 0, (_fs->GetCurrentPos() - jmppos), 0);
+            _fs->SetInstructionParams(jmppos, 0, (_fs->GetCurrentPos() - jmppos), 0);
             END_SCOPE();
             END_SCOPE();
         }
         }
     }
     }
@@ -1548,7 +1548,7 @@ public:
             SQInteger pos = funcstate->_unresolvedbreaks.back();
             SQInteger pos = funcstate->_unresolvedbreaks.back();
             funcstate->_unresolvedbreaks.pop_back();
             funcstate->_unresolvedbreaks.pop_back();
             //set the jmp instruction
             //set the jmp instruction
-            funcstate->SetIntructionParams(pos, 0, funcstate->GetCurrentPos() - pos, 0);
+            funcstate->SetInstructionParams(pos, 0, funcstate->GetCurrentPos() - pos, 0);
             ntoresolve--;
             ntoresolve--;
         }
         }
     }
     }
@@ -1558,7 +1558,7 @@ public:
             SQInteger pos = funcstate->_unresolvedcontinues.back();
             SQInteger pos = funcstate->_unresolvedcontinues.back();
             funcstate->_unresolvedcontinues.pop_back();
             funcstate->_unresolvedcontinues.pop_back();
             //set the jmp instruction
             //set the jmp instruction
-            funcstate->SetIntructionParams(pos, 0, targetpos - pos, 0);
+            funcstate->SetInstructionParams(pos, 0, targetpos - pos, 0);
             ntoresolve--;
             ntoresolve--;
         }
         }
     }
     }

+ 2 - 2
squirrel/sqfuncstate.cpp

@@ -238,7 +238,7 @@ SQInteger SQFuncState::GetConstant(const SQObject &cons)
     return _integer(val);
     return _integer(val);
 }
 }
 
 
-void SQFuncState::SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2,SQInteger arg3)
+void SQFuncState::SetInstructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2,SQInteger arg3)
 {
 {
     _instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&arg0);
     _instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&arg0);
     _instructions[pos]._arg1=(SQInt32)*((SQUnsignedInteger *)&arg1);
     _instructions[pos]._arg1=(SQInt32)*((SQUnsignedInteger *)&arg1);
@@ -246,7 +246,7 @@ void SQFuncState::SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg
     _instructions[pos]._arg3=(unsigned char)*((SQUnsignedInteger *)&arg3);
     _instructions[pos]._arg3=(unsigned char)*((SQUnsignedInteger *)&arg3);
 }
 }
 
 
-void SQFuncState::SetIntructionParam(SQInteger pos,SQInteger arg,SQInteger val)
+void SQFuncState::SetInstructionParam(SQInteger pos,SQInteger arg,SQInteger val)
 {
 {
     switch(arg){
     switch(arg){
         case 0:_instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&val);break;
         case 0:_instructions[pos]._arg0=(unsigned char)*((SQUnsignedInteger *)&val);break;

+ 2 - 2
squirrel/sqfuncstate.h

@@ -16,8 +16,8 @@ struct SQFuncState
     void PopChildState();
     void PopChildState();
     void AddInstruction(SQOpcode _op,SQInteger arg0=0,SQInteger arg1=0,SQInteger arg2=0,SQInteger arg3=0){SQInstruction i(_op,arg0,arg1,arg2,arg3);AddInstruction(i);}
     void AddInstruction(SQOpcode _op,SQInteger arg0=0,SQInteger arg1=0,SQInteger arg2=0,SQInteger arg3=0){SQInstruction i(_op,arg0,arg1,arg2,arg3);AddInstruction(i);}
     void AddInstruction(SQInstruction &i);
     void AddInstruction(SQInstruction &i);
-    void SetIntructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2=0,SQInteger arg3=0);
-    void SetIntructionParam(SQInteger pos,SQInteger arg,SQInteger val);
+    void SetInstructionParams(SQInteger pos,SQInteger arg0,SQInteger arg1,SQInteger arg2=0,SQInteger arg3=0);
+    void SetInstructionParam(SQInteger pos,SQInteger arg,SQInteger val);
     SQInstruction &GetInstruction(SQInteger pos){return _instructions[pos];}
     SQInstruction &GetInstruction(SQInteger pos){return _instructions[pos];}
     void PopInstructions(SQInteger size){for(SQInteger i=0;i<size;i++)_instructions.pop_back();}
     void PopInstructions(SQInteger size){for(SQInteger i=0;i<size;i++)_instructions.pop_back();}
     void SetStackSize(SQInteger n);
     void SetStackSize(SQInteger n);

+ 2 - 2
squirrel/sqobject.cpp

@@ -285,7 +285,7 @@ bool SafeWrite(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQUserPointer de
     return true;
     return true;
 }
 }
 
 
-bool SafeRead(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQUserPointer dest,SQInteger size)
+bool SafeRead(HSQUIRRELVM v,SQREADFUNC read,SQUserPointer up,SQUserPointer dest,SQInteger size)
 {
 {
     if(size && read(up,dest,size) != size) {
     if(size && read(up,dest,size) != size) {
         v->Raise_Error(_SC("io error, read function failure, the origin stream could be corrupted/trucated"));
         v->Raise_Error(_SC("io error, read function failure, the origin stream could be corrupted/trucated"));
@@ -299,7 +299,7 @@ bool WriteTag(HSQUIRRELVM v,SQWRITEFUNC write,SQUserPointer up,SQUnsignedInteger
     return SafeWrite(v,write,up,&tag,sizeof(tag));
     return SafeWrite(v,write,up,&tag,sizeof(tag));
 }
 }
 
 
-bool CheckTag(HSQUIRRELVM v,SQWRITEFUNC read,SQUserPointer up,SQUnsignedInteger32 tag)
+bool CheckTag(HSQUIRRELVM v,SQREADFUNC read,SQUserPointer up,SQUnsignedInteger32 tag)
 {
 {
     SQUnsignedInteger32 t;
     SQUnsignedInteger32 t;
     _CHECK_IO(SafeRead(v,read,up,&t,sizeof(t)));
     _CHECK_IO(SafeRead(v,read,up,&t,sizeof(t)));

+ 5 - 3
squirrel/sqvm.cpp

@@ -383,7 +383,8 @@ bool SQVM::StartCall(SQClosure *closure,SQInteger target,SQInteger args,SQIntege
     {
     {
         paramssize--;
         paramssize--;
         if (nargs < paramssize) {
         if (nargs < paramssize) {
-            Raise_Error(_SC("wrong number of parameters"));
+            Raise_Error(_SC("wrong number of parameters (%d passed, at least %d required)"),
+              (int)nargs, (int)paramssize);
             return false;
             return false;
         }
         }
 
 
@@ -409,7 +410,8 @@ bool SQVM::StartCall(SQClosure *closure,SQInteger target,SQInteger args,SQIntege
             }
             }
         }
         }
         else {
         else {
-            Raise_Error(_SC("wrong number of parameters"));
+            Raise_Error(_SC("wrong number of parameters (%d passed, %d required)"),
+              (int)nargs, (int)paramssize);
             return false;
             return false;
         }
         }
     }
     }
@@ -1358,7 +1360,7 @@ bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr
             return false;
             return false;
         }
         }
         return true;
         return true;
-    case OT_USERDATA: break; // must fall back
+  	case OT_USERDATA: break; // must fall back
     default:
     default:
         Raise_Error(_SC("trying to set '%s'"),GetTypeName(self));
         Raise_Error(_SC("trying to set '%s'"),GetTypeName(self));
         return false;
         return false;