This commit is contained in:
albertodemichelis 2016-07-30 19:09:53 +08:00
commit 17124aa789
15 changed files with 146 additions and 125 deletions

View File

@ -91,7 +91,7 @@ resizes the array at the position idx in the stack.
:returns: a SQRESULT :returns: a SQRESULT
:remarks: Only works on arrays. :remarks: Only works on arrays.
reverse an array in place. reverses an array in place.
@ -106,7 +106,7 @@ reverse an array in place.
:returns: a SQRESULT :returns: a SQRESULT
:remarks: Only works on tables and arrays. :remarks: Only works on tables and arrays.
clears all the element of the table/array at position idx in the stack. clears all the elements of the table/array at position idx in the stack.
@ -120,7 +120,7 @@ clears all the element of the table/array at position idx in the stack.
: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
Clones the table, array or class instance at the position idx, clones it and pushes the new object in the stack. pushes a clone of the table, array, or class instance at the position idx.
@ -446,6 +446,6 @@ pops a value from the stack and sets it as a free variable of the closure at the
:param HSQUIRRELVM v: the target VM :param HSQUIRRELVM v: the target VM
:param SQInteger idx: index to the target object in the stack :param SQInteger idx: index to the target object in the stack
:returns: a SQRESULT :returns: a SQRESULT
:remarks: if the object at idx position is an integer,float,bool or null the object itself is pushed instead of a weak ref. :remarks: if the object at idx position is one of (integer, float, bool, null), the object itself is pushed instead of a weak ref.
pushes a weak reference to the object at position idx in the stack. pushes a weak reference to the object at position idx in the stack.

View File

@ -7,10 +7,10 @@ Introduction
.. index:: .. index::
single: introduction single: introduction
Squirrel is a high level imperative-OO programming language, designed to be a powerful Squirrel is a high-level, imperative-OO programming language, designed to be a powerful
scripting tool that fits in the size, memory bandwidth, and real-time requirements of scripting tool that fits within the size, memory bandwidth, and real-time requirements of
applications like games. applications like games.
Although Squirrel offers a wide range of features like dynamic typing, delegation, higher Squirrel offers a wide range of features like dynamic typing, delegation, higher
order functions, generators, tail recursion, exception handling, automatic memory order functions, generators, tail recursion, exception handling, automatic memory
management, both compiler and virtual machine fit together in about 6k lines of C++ management while fitting both compiler and virtual machine into about 6k lines of C++
code. code.

View File

@ -16,8 +16,7 @@ Global Symbols
.. js:function:: array(size,[fill]) .. js:function:: array(size,[fill])
create and returns array of a specified size.if the optional parameter fill is specified its creates and returns array of a specified size. If the optional parameter fill is specified its value will be used to fill the new array's slots. If the fill parameter is omitted, null is used instead.
value will be used to fill the new array's slots. If the fill parameter is omitted null is used instead.
.. js:function:: seterrorhandler(func) .. js:function:: seterrorhandler(func)
@ -76,11 +75,11 @@ compiles a string containing a squirrel script into a function and returns it::
.. js:function:: collectgarbage() .. js:function:: collectgarbage()
runs the garbage collector and returns the number of reference cycles found(and deleted) This function only works on garbage collector builds. Runs the garbage collector and returns the number of reference cycles found (and deleted). This function only works on garbage collector builds.
.. js:function:: resurrectunreachable() .. js:function:: resurrectunreachable()
runs the garbage collector and returns an array containing all unreachable object found. If no unreachable object is found, null is returned instead. This function is meant to help debugging reference cycles. This function only works on garbage collector builds. Runs the garbage collector and returns an array containing all unreachable object found. If no unreachable object is found, null is returned instead. This function is meant to help debugging reference cycles. This function only works on garbage collector builds.
.. js:function:: type(obj) .. js:function:: type(obj)
@ -105,7 +104,7 @@ returns the stack informations of a given call stack level. returns a table form
} }
} }
level = 0 is the current function, level = 1 is the caller and so on. If the stack level doesn't exist the function returns null. level = 0 is getstackinfos() itself! level = 1 is the current function, level = 2 is the caller of the current function, and so on. If the stack level doesn't exist the function returns null.
.. js:function:: newthread(threadfunc) .. js:function:: newthread(threadfunc)
@ -113,7 +112,7 @@ creates a new cooperative thread object(coroutine) and returns it
.. js:data:: _versionnumber_ .. js:data:: _versionnumber_
integer values describing the version of VM and compiler. eg. for Squirrel 3.0.1 this value will be 301 integer values describing the version of VM and compiler. e.g. for Squirrel 3.0.1 this value will be 301
.. js:data:: _version_ .. js:data:: _version_
@ -153,7 +152,7 @@ converts the number to string and returns it
.. js:function:: integer.tointeger() .. js:function:: integer.tointeger()
returns the value of the integer(dummy function) dummy function; returns the value of the integer.
.. js:function:: integer.tochar() .. js:function:: integer.tochar()
@ -163,7 +162,7 @@ returns a string containing a single character represented by the integer.
.. js:function:: integer.weakref() .. js:function:: integer.weakref()
dummy function, returns the integer itself. dummy function; returns the integer itself.
^^^^^ ^^^^^
Float Float
@ -191,7 +190,7 @@ returns a string containing a single character represented by the integer part o
.. js:function:: float.weakref() .. js:function:: float.weakref()
dummy function, returns the float itself. dummy function; returns the float itself.
^^^^ ^^^^
Bool Bool
@ -209,12 +208,12 @@ returns 1 for true 0 for false
.. js:function:: bool.tostring() .. js:function:: bool.tostring()
returns "true" for true "false" for false returns "true" for true and "false" for false
.. js:function:: bool.weakref() .. js:function:: bool.weakref()
dummy function, returns the bool itself. dummy function; returns the bool itself.
^^^^^^ ^^^^^^
String String
@ -227,7 +226,7 @@ returns the string length
.. js:function:: string.tointeger([base]) .. js:function:: string.tointeger([base])
converts the string to integer and returns it.An optional parameter base can be specified, if a base is not specified it defaults to base 10 Converts the string to integer and returns it. An optional parameter base can be specified--if a base is not specified, it defaults to base 10.
.. js:function:: string.tofloat() .. js:function:: string.tofloat()
@ -237,7 +236,7 @@ converts the string to float and returns it
.. js:function:: string.tostring() .. js:function:: string.tostring()
returns the string(dummy function) returns the string (really, a dummy function)
.. js:function:: string.slice(start,[end]) .. js:function:: string.slice(start,[end])
@ -247,7 +246,7 @@ returns a section of the string as new string. Copies from start to the end (not
.. js:function:: string.find(substr,[startidx]) .. js:function:: string.find(substr,[startidx])
search a sub string(substr) starting from the index startidx and returns the index of its first occurrence. If startidx is omitted the search operation starts from the beginning of the string. The function returns null if substr is not found. Searches a sub string (substr) starting from the index startidx and returns the index of its first occurrence. If startidx is omitted the search operation starts from the beginning of the string. The function returns null if substr is not found.
.. js:function:: string.tolower() .. js:function:: string.tolower()
@ -280,12 +279,12 @@ 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.
.. js:function:: table.rawdelete() .. js:function:: table.rawdelete()
deletes the slot key without employing delegation and returns his value. if the slo does not exists returns always null. Deletes the slot key without employing delegation and returns its value. If the slot does not exists, returns null.
.. js:function:: table.rawin(key) .. js:function:: table.rawin(key)
@ -300,17 +299,17 @@ returns a weak reference to the object.
.. js:function:: table.tostring() .. js:function:: table.tostring()
tries to invoke the _tostring metamethod, if failed. returns "(table : pointer)". Tries to invoke the _tostring metamethod. If that fails, it returns "(table : pointer)".
.. js:function:: table.clear() .. js:function:: table.clear()
removes all the slot from the table removes all the slots from the table
.. js:function:: table.setdelegate(table) .. js:function:: table.setdelegate(table)
sets the delegate of the table, to remove a delegate 'null' must be passed to the function. The function returns the table itself (eg. a.setdelegate(b) in this case 'a' is the return value). Sets the delegate of the table. To remove a delegate, 'null' must be passed to the function. The function returns the table itself (e.g. a.setdelegate(b) -- in this case 'a' is the return value).
.. js:function:: table.getdelegate() .. js:function:: table.getdelegate()
@ -363,12 +362,12 @@ removes the value at the position 'idx' in the array
.. 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 (if 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.
.. 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. 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)
{ {
@ -390,7 +389,7 @@ reverse the elements of the array in place
.. js:function:: array.slice(start,[end]) .. js:function:: array.slice(start,[end])
returns a section of the array as new array. Copies from start to the end (not included). If start is negative the index is calculated as length + start, if end is negative the index is calculated as length + end. If end is omitted end is equal to the array length. Returns a section of the array as new array. Copies from start to the end (not included). If start is negative the index is calculated as length + start, if end is negative the index is calculated as length + end. If end is omitted end is equal to the array length.
.. js:function:: array.weakref() .. js:function:: array.weakref()
@ -410,7 +409,7 @@ removes all the items from the array
.. js:function:: array.map(func(a)) .. js:function:: array.map(func(a))
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.
.. js:function:: array.apply(func(a)) .. js:function:: array.apply(func(a))
@ -436,52 +435,52 @@ Performs a linear search for the value in the array. Returns the index of the va
Function Function
^^^^^^^^ ^^^^^^^^
.. js:function:: array.call(_this,args...) .. js:function:: function.call(_this,args...)
calls the function with the specified environment object('this') and parameters calls the function with the specified environment object('this') and parameters
.. js:function:: array.pcall(_this,args...) .. js:function:: function.pcall(_this,args...)
calls the function with the specified environment object('this') and parameters, this function will not invoke the error callback in case of failure(pcall stays for 'protected call') calls the function with the specified environment object('this') and parameters, this function will not invoke the error callback in case of failure(pcall stays for 'protected call')
.. js:function:: array.acall(array_args) .. js:function:: function.acall(array_args)
calls the function with the specified environment object('this') and parameters. The function accepts an array containing the parameters that will be passed to the called function.Where array_args has to contain the required 'this' object at the [0] position. calls the function with the specified environment object('this') and parameters. The function accepts an array containing the parameters that will be passed to the called function.Where array_args has to contain the required 'this' object at the [0] position.
.. js:function:: array.pacall(array_args) .. js:function:: function.pacall(array_args)
calls the function with the specified environment object('this') and parameters. The function accepts an array containing the parameters that will be passed to the called function.Where array_args has to contain the required 'this' object at the [0] position. This function will not invoke the error callback in case of failure(pacall stays for 'protected array call') calls the function with the specified environment object('this') and parameters. The function accepts an array containing the parameters that will be passed to the called function.Where array_args has to contain the required 'this' object at the [0] position. This function will not invoke the error callback in case of failure(pacall stays for 'protected array call')
.. js:function:: array.weakref() .. js:function:: function.weakref()
returns a weak reference to the object. returns a weak reference to the object.
.. js:function:: array.tostring() .. js:function:: function.tostring()
returns the string "(closure : pointer)". returns the string "(closure : pointer)".
.. js:function:: array.setroot(table) .. js:function:: function.setroot(table)
sets the root table of a closure sets the root table of a closure
.. js:function:: array.getroot() .. js:function:: function.getroot()
returns the root table of the closure returns the root table of the closure
.. js:function:: array.bindenv(env) .. js:function:: function.bindenv(env)
clones the function(aka closure) and bind the environment object to it(table,class or instance). the this parameter of the newly create function will always be set to env. Note that the created function holds a weak reference to its environment object so cannot be used to control its lifetime. clones the function(aka closure) and bind the environment object to it(table,class or instance). the this parameter of the newly create function will always be set to env. Note that the created function holds a weak reference to its environment object so cannot be used to control its lifetime.
.. js:function:: array.getinfos() .. js:function:: function.getinfos()
returns a table containing informations about the function, like parameters, name and source name; :: returns a table containing informations about the function, like parameters, name and source name; ::

View File

@ -46,7 +46,7 @@ For instance: ::
} }
the previous code examples is a syntactic sugar for: :: the previous code example is a syntactic sugar for: ::
Foo <- class { Foo <- class {
//constructor //constructor
@ -67,7 +67,7 @@ the previous code examples is a syntactic sugar for: ::
} }
in order to emulate namespaces, is also possible to declare something like this:: in order to emulate namespaces, it is also possible to declare something like this::
//just 2 regular nested tables //just 2 regular nested tables
FakeNamespace <- { FakeNamespace <- {

View File

@ -4,10 +4,11 @@
Values and Data types Values and Data types
===================== =====================
Squirrel is a dynamically typed language so variables do not have a type, although they While Squirrel is a dynamically typed language and variables do not
refer to a value that does have a type. have a type, different operations may interpret the variable as
Squirrel basic types are integer, float, string, null, table, array, function, generator, containing a type. Squirrel's basic types are integer, float, string,
class, instance, bool, thread and userdata. null, table, array, function, generator, class, instance, bool, thread
and userdata.
.. _userdata-index: .. _userdata-index:
@ -15,7 +16,7 @@ class, instance, bool, thread and userdata.
Integer Integer
-------- --------
An Integer represents a 32 bits (or better) signed number.:: An Integer represents a 32 bit (or better) signed number.::
local a = 123 //decimal local a = 123 //decimal
local b = 0x0012 //hexadecimal local b = 0x0012 //hexadecimal
@ -26,7 +27,7 @@ An Integer represents a 32 bits (or better) signed number.::
Float Float
-------- --------
A float represents a 32 bits (or better) floating point number.:: A float represents a 32 bit (or better) floating point number.::
local a=1.0 local a=1.0
local b=0.234 local b=0.234
@ -35,24 +36,27 @@ A float represents a 32 bits (or better) floating point number.::
String String
-------- --------
Strings are an immutable sequence of characters to modify a string is necessary create a new one. Strings are an immutable sequence of characters. In order to modify a
string is it necessary create a new one.
Squirrel's strings, behave like C or C++, are delimited by quotation marks(``"``) and can contain Squirrel's strings are similar to strings in C or C++. They are
escape sequences(``\t``, ``\a``, ``\b``, ``\n``, ``\r``, ``\v``, ``\f``, ``\\``, ``\"``, ``\'``, ``\0``, delimited by quotation marks(``"``) and can contain escape
``\x<hh>``, ``\u<hhhh>`` and ``\U<hhhhhhhh>``). sequences (``\t``, ``\a``, ``\b``, ``\n``, ``\r``, ``\v``, ``\f``,
``\\``, ``\"``, ``\'``, ``\0``, ``\x<hh>``, ``\u<hhhh>`` and
``\U<hhhhhhhh>``).
Verbatim string literals begin with ``@"`` and end with the matching quote. Verbatim string literals do not interpret escape sequences. They begin
Verbatim string literals also can extend over a line break. If they do, they with ``@"`` and end with the matching quote. Verbatim string literals
include any white space characters between the quotes: :: also can extend over a line break. If they do, they include any white
space characters between the quotes: ::
local a = "I'm a wonderful string\n" local a = "I'm a wonderful string\n"
// has a newline at the end of the string // has a newline at the end of the string
local x = @"I'm a verbatim string\n" local x = @"I'm a verbatim string\n"
// the \n is copied in the string same as \\n in a regular string "I'm a verbatim string\n" // the \n is literal, similar to "\\n" in a regular string.
The only exception to the "no escape sequence" rule for verbatim However, a doubled quotation mark within a verbatim string is replaced
string literals is that you can put a double quotation mark inside a by a single quotation mark: ::
verbatim string by doubling it: ::
local multiline = @" local multiline = @"
this is a multiline string this is a multiline string
@ -73,7 +77,7 @@ reference. The type Null has exactly one value, called null.::
Bool Bool
-------- --------
the bool data type can have only two. They are the literals ``true`` Bool is a double-valued (Boolean) data type. Its literals are ``true``
and ``false``. A bool value expresses the validity of a condition and ``false``. A bool value expresses the validity of a condition
(tells whether the condition is true or false).:: (tells whether the condition is true or false).::
@ -83,7 +87,8 @@ and ``false``. A bool value expresses the validity of a condition
Table Table
-------- --------
Tables are associative containers implemented as pairs of key/value (called a slot).:: Tables are associative containers implemented as a set of key/value pairs
called slots.::
local t={} local t={}
local test= local test=
@ -96,7 +101,7 @@ Tables are associative containers implemented as pairs of key/value (called a sl
Array Array
-------- --------
Arrays are simple sequence of objects, their size is dynamic and their index starts always from 0.:: Arrays are simple sequence of objects. Their size is dynamic and their index always starts from 0.::
local a = ["I'm","an","array"] local a = ["I'm","an","array"]
local b = [null] local b = [null]
@ -106,46 +111,48 @@ Arrays are simple sequence of objects, their size is dynamic and their index sta
Function Function
-------- --------
Functions are similar to those in other C-like languages and to most programming Functions are similar to those in other C-like languages with a few key differences (see below).
languages in general, however there are a few key differences (see below).
-------- --------
Class Class
-------- --------
Classes are associative containers implemented as pairs of key/value. Classes are created through Classes are associative containers implemented as sets of key/value
a 'class expression' or a 'class statement'. class members can be inherited from another class object pairs. Classes are created through a 'class expression' or a 'class
at creation time. After creation members can be added until a instance of the class is created. statement'. class members can be inherited from another class object
at creation time. After creation, members can be added until an
instance of the class is created.
-------------- --------------
Class Instance Class Instance
-------------- --------------
Class instances are created by calling a *class object*. Instances, as tables, are Class instances are created by calling a *class object*. Instances, as
implemented as pair of key/value. Instances members cannot be dynamically added or removed; however the value of the members can be changed. tables, are implemented as sets of key/value pairs. Instance members
cannot be dynamically added or removed; however the value of the
members can be changed.
--------- ---------
Generator Generator
--------- ---------
Generators are functions that can be suspended with the statement 'yield' and resumed Generators are functions that can be suspended with the statement
later (see :ref:`Generators <generators>`). 'yield' and resumed later (see :ref:`Generators <generators>`).
--------- ---------
Userdata Userdata
--------- ---------
Userdata objects are blobs of memory(or pointers) defined by the host application but Userdata objects are blobs of memory or pointers defined by the host
stored into Squirrel variables (See :ref:`Userdata and UserPointers <embedding_userdata_and_userpointers>`). application but stored within Squirrel variables (See :ref:`Userdata
and UserPointers <embedding_userdata_and_userpointers>`).
--------- ---------
Thread Thread
--------- ---------
Threads are objects that represents a cooperative thread of execution, also known as coroutines. Threads are objects representing a cooperative thread of execution,
also known as coroutines.
-------------- --------------
Weak Reference Weak Reference
@ -153,5 +160,3 @@ Weak Reference
Weak References are objects that point to another (non-scalar) object but do not own a strong reference to it. Weak References are objects that point to another (non-scalar) object but do not own a strong reference to it.
(See :ref:`Weak References <weak_references>`). (See :ref:`Weak References <weak_references>`).

View File

@ -221,10 +221,10 @@ Bitwise Operators
exp:= 'exp' op 'exp' exp:= 'exp' op 'exp'
exp := '~' exp exp := '~' exp
Squirrel supports the standard c-like bit wise operators ``&, |, ^, ~, <<, >>`` plus the unsigned Squirrel supports the standard C-like bitwise operators ``&, |, ^, ~, <<, >>`` plus the unsigned
right shift operator ``<<<``. The unsigned right shift works exactly like the normal right shift operator(``<<``) right shift operator ``>>>``. The unsigned right shift works exactly like the normal right shift operator(``>>``)
except for treating the left operand as an unsigned integer, so is not affected by the sign. Those operators except for treating the left operand as an unsigned integer, so is not affected by the sign. Those operators
only work on integers values, passing of any other operand type to these operators will only work on integer values; passing of any other operand type to these operators will
cause an exception. cause an exception.
^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^
@ -293,7 +293,7 @@ A new slot with exp1 as key and exp2 as value is created::
[1]="I'm the value" [1]="I'm the value"
} }
both syntaxes can be mixed:: Both syntaxes can be mixed::
local table= local table=
{ {
@ -369,6 +369,6 @@ Creates a new array.::
a <- [] //creates an empty array a <- [] //creates an empty array
arrays can be initialized with values during the construction:: Arrays can be initialized with values during the construction::
a <- [1,"string!",[],{}] //creates an array with 4 elements a <- [1,"string!",[],{}] //creates an array with 4 elements

View File

@ -140,19 +140,31 @@ Function calls
The expression is evaluated in this order: derefexp after the explist (arguments) and at The expression is evaluated in this order: derefexp after the explist (arguments) and at
the end the call. the end the call.
Every function call in Squirrel passes the environment object *this* as hidden parameter A function call in Squirrel passes the current environment object *this* as a hidden parameter.
to the called function. The 'this' parameter is the object where the function was indexed But when the function was immediately indexed from an object, *this* shall be the object
from. which was indexed, instead.
If we call a function with this syntax:: If we call a function with the syntax::
table.foo(a) mytable.foo(x,y)
the environment object passed to foo will be 'table':: the environment object passed to 'foo' as *this* will be 'mytable' (since 'foo' was immediately indexed from 'mytable')
foo(x,y) // equivalent to this.foo(x,y) Whereas with the syntax::
The environment object will be *this* (the same of the caller function). foo(x,y) // implicitly equivalent to this.foo(x,y)
the environment object will be the current *this* (that is, propagated from the caller's *this*).
It may help to remember the rules in the following way:
foo(x,y) ---> this.foo(x,y)
table.foo(x,y) ---> call foo with (table,x,y)
It may also help to consider why it works this way: it's designed to assist with object-oriented style.
When calling 'foo(x,y)' it's assumed you're calling another member of the object (or of the file) and
so should operate on the same object.
When calling 'mytable.foo(x,y)' it's written plainly that you're calling a member of a different object.
--------------------------------------------- ---------------------------------------------
Binding an environment to a function Binding an environment to a function
@ -184,7 +196,7 @@ Lambda Expressions
exp := '@' '(' paramlist ')' exp exp := '@' '(' paramlist ')' exp
Lambda expressions are a synctactic sugar to quickly define a function that consists of a single expression. Lambda expressions are a syntactic sugar to quickly define a function that consists of a single expression.
This feature comes handy when functional programming patterns are applied, like map/reduce or passing a compare method to This feature comes handy when functional programming patterns are applied, like map/reduce or passing a compare method to
array.sort(). array.sort().

View File

@ -13,11 +13,11 @@ Identifiers
.. index:: single: identifiers .. index:: single: identifiers
Identifiers start with a alphabetic character or '_' followed by any number of alphabetic Identifiers start with an alphabetic character or the symbol '_' followed by any number
characters, '_' or digits ([0-9]). Squirrel is a case sensitive language, this means that the of alphabetic characters, '_' or digits ([0-9]). Squirrel is a case sensitive language
lowercase and uppercase representation of the same alphabetic character are considered meaning that the lowercase and uppercase representation of the same alphabetic
different characters. For instance "foo", "Foo" and "fOo" will be treated as 3 distinct character are considered different characters. For instance, "foo", "Foo" and "fOo" are
identifiers. treated as 3 distinct identifiers.
----------- -----------
Keywords Keywords
@ -25,7 +25,7 @@ Keywords
.. index:: single: keywords .. index:: single: keywords
The following words are reserved words by the language and cannot be used as identifiers: The following words are reserved and cannot be used as identifiers:
+------------+------------+-----------+------------+------------+-------------+ +------------+------------+-----------+------------+------------+-------------+
| base | break | case | catch | class | clone | | base | break | case | catch | class | clone |
@ -69,7 +69,7 @@ Other tokens
single: delimiters single: delimiters
single: other tokens single: other tokens
Other used tokens are: Other significant tokens are:
+----------+----------+----------+----------+----------+----------+ +----------+----------+----------+----------+----------+----------+
| ``{`` | ``}`` | ``[`` | ``]`` | ``.`` | ``:`` | | ``{`` | ``}`` | ``[`` | ``]`` | ``.`` | ``:`` |
@ -86,7 +86,7 @@ Literals
single: string literals single: string literals
single: numeric literals single: numeric literals
Squirrel accepts integer numbers, floating point numbers and strings literals. Squirrel accepts integer numbers, floating point numbers and string literals.
+-------------------------------+------------------------------------------+ +-------------------------------+------------------------------------------+
| ``34`` | Integer number(base 10) | | ``34`` | Integer number(base 10) |
@ -131,7 +131,7 @@ A comment is text that the compiler ignores but that is useful for programmers.
Comments are normally used to embed annotations in the code. The compiler Comments are normally used to embed annotations in the code. The compiler
treats them as white space. treats them as white space.
The ``/*`` (slash, asterisk) characters, followed by any A comment can be ``/*`` (slash, asterisk) characters, followed by any
sequence of characters (including new lines), sequence of characters (including new lines),
followed by the ``*/`` characters. This syntax is the same as ANSI C.:: followed by the ``*/`` characters. This syntax is the same as ANSI C.::
@ -141,9 +141,9 @@ followed by the ``*/`` characters. This syntax is the same as ANSI C.::
this lines will be ignored by the compiler this lines will be ignored by the compiler
*/ */
The ``//`` (two slashes) characters, followed by any sequence of characters. A comment can also be ``//`` (two slashes) characters, followed by any sequence of
A new line not immediately preceded by a backslash terminates this form of comment. characters. A new line not immediately preceded by a backslash terminates this form of
It is commonly called a *"single-line comment."*:: comment. It is commonly called a *"single-line comment."*::
//this is a single line comment. this line will be ignored by the compiler //this is a single line comment. this line will be ignored by the compiler
@ -152,5 +152,3 @@ The character ``#`` is an alternative syntax for single line comment.::
# this is also a single line comment. # this is also a single line comment.
This to facilitate the use of squirrel in UNIX-style shell scripts. This to facilitate the use of squirrel in UNIX-style shell scripts.

View File

@ -226,7 +226,7 @@ _nexti
_nexti(previdx) _nexti(previdx)
invoked when a userdata or class instance is iterated by a foreach loop invoked when a userdata or class instance is iterated by a foreach loop.
If previdx==null it means that it is the first iteration. If previdx==null it means that it is the first iteration.
The function has to return the index of the 'next' value. The function has to return the index of the 'next' value.
@ -237,10 +237,10 @@ _tostring
:: ::
_tostring(previdx) _tostring()
invoked when during string concatenation or when the ``print`` function prints a table, instance, or userdata. Invoked when during string concatenation or when the ``print`` function prints a table, instance, or userdata.
The method is also invoked by the sq_tostring() API The method is also invoked by the sq_tostring() API.
Must return a string representation of the object. Must return a string representation of the object.

View File

@ -22,6 +22,10 @@ THE SOFTWARE.
#ifndef _SQUIRREL_H_ #ifndef _SQUIRREL_H_
#define _SQUIRREL_H_ #define _SQUIRREL_H_
#ifdef _SQ_CONFIG_INCLUDE
#include _SQ_CONFIG_INCLUDE
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -396,7 +400,7 @@ SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook);
#ifdef __GNUC__ #ifdef __GNUC__
# define SQ_UNUSED_ARG(x) __attribute__((unused)) x # define SQ_UNUSED_ARG(x) __attribute__((unused)) x
#else #else
# define SQ_UNUSED_ARG(x) x # define SQ_UNUSED_ARG(x)
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -52,7 +52,6 @@ void printfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...)
va_start(vl, s); va_start(vl, s);
scvprintf(stdout, s, vl); scvprintf(stdout, s, vl);
va_end(vl); va_end(vl);
(void)v; /* UNUSED */
} }
void errorfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...) void errorfunc(HSQUIRRELVM SQ_UNUSED_ARG(v),const SQChar *s,...)

View File

@ -510,7 +510,7 @@ SQRESULT sq_setclosureroot(HSQUIRRELVM v,SQInteger idx)
v->Pop(); v->Pop();
return SQ_OK; return SQ_OK;
} }
return sq_throwerror(v, _SC("ivalid type")); return sq_throwerror(v, _SC("invalid type"));
} }
SQRESULT sq_getclosureroot(HSQUIRRELVM v,SQInteger idx) SQRESULT sq_getclosureroot(HSQUIRRELVM v,SQInteger idx)
@ -558,7 +558,7 @@ SQRESULT sq_setroottable(HSQUIRRELVM v)
v->Pop(); v->Pop();
return SQ_OK; return SQ_OK;
} }
return sq_throwerror(v, _SC("ivalid type")); return sq_throwerror(v, _SC("invalid type"));
} }
SQRESULT sq_setconsttable(HSQUIRRELVM v) SQRESULT sq_setconsttable(HSQUIRRELVM v)
@ -569,7 +569,7 @@ SQRESULT sq_setconsttable(HSQUIRRELVM v)
v->Pop(); v->Pop();
return SQ_OK; return SQ_OK;
} }
return sq_throwerror(v, _SC("ivalid type, expected table")); return sq_throwerror(v, _SC("invalid type, expected table"));
} }
void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p) void sq_setforeignptr(HSQUIRRELVM v,SQUserPointer p)
@ -657,6 +657,10 @@ SQRESULT sq_getinteger(HSQUIRRELVM v,SQInteger idx,SQInteger *i)
*i = tointeger(o); *i = tointeger(o);
return SQ_OK; return SQ_OK;
} }
if(sq_isbool(o)) {
*i = SQVM::IsFalse(o)?SQFalse:SQTrue;
return SQ_OK;
}
return SQ_ERROR; return SQ_ERROR;
} }
@ -1164,7 +1168,7 @@ SQRESULT sq_call(HSQUIRRELVM v,SQInteger params,SQBool retval,SQBool raiseerror)
if(v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){ if(v->Call(v->GetUp(-(params+1)),params,v->_top-params,res,raiseerror?true:false)){
if(!v->_suspended) { if(!v->_suspended) {
v->Pop(params);//pop closure and args v->Pop(params);//pop args
} }
if(retval){ if(retval){
v->Push(res); return SQ_OK; v->Push(res); return SQ_OK;
@ -1239,7 +1243,7 @@ SQRESULT sq_writeclosure(HSQUIRRELVM v,SQWRITEFUNC w,SQUserPointer up)
_GETSAFE_OBJ(v, -1, OT_CLOSURE,o); _GETSAFE_OBJ(v, -1, OT_CLOSURE,o);
unsigned short tag = SQ_BYTECODE_STREAM_TAG; unsigned short tag = SQ_BYTECODE_STREAM_TAG;
if(_closure(*o)->_function->_noutervalues) if(_closure(*o)->_function->_noutervalues)
return sq_throwerror(v,_SC("a closure with free valiables bound it cannot be serialized")); return sq_throwerror(v,_SC("a closure with free variables bound cannot be serialized"));
if(w(up,&tag,2) != 2) if(w(up,&tag,2) != 2)
return sq_throwerror(v,_SC("io error")); return sq_throwerror(v,_SC("io error"));
if(!_closure(*o)->Save(v,up,w)) if(!_closure(*o)->Save(v,up,w))

View File

@ -189,7 +189,7 @@ SQInstance::~SQInstance()
if(_class){ Finalize(); } //if _class is null it was already finalized by the GC if(_class){ Finalize(); } //if _class is null it was already finalized by the GC
} }
bool SQInstance::GetMetaMethod(SQVM SQ_UNUSED_ARG(*v),SQMetaMethod mm,SQObjectPtr &res) bool SQInstance::GetMetaMethod(SQVM* SQ_UNUSED_ARG(v),SQMetaMethod mm,SQObjectPtr &res)
{ {
if(type(_class->_metamethods[mm]) != OT_NULL) { if(type(_class->_metamethods[mm]) != OT_NULL) {
res = _class->_metamethods[mm]; res = _class->_metamethods[mm];

View File

@ -1346,7 +1346,7 @@ public:
} }
break; break;
default: default:
Error(_SC("scalar expected : integer,float or string")); Error(_SC("scalar expected : integer, float, or string"));
} }
Lex(); Lex();
return val; return val;

View File

@ -241,7 +241,7 @@ void SQSharedState::MarkObject(SQObjectPtr &o,SQCollectable **chain)
} }
} }
void SQSharedState::RunMark(SQVM SQ_UNUSED_ARG(*vm),SQCollectable **tchain) void SQSharedState::RunMark(SQVM* SQ_UNUSED_ARG(vm),SQCollectable **tchain)
{ {
SQVM *vms = _thread(_root_vm); SQVM *vms = _thread(_root_vm);