File: calls.rst

package info (click to toggle)
supertux 0.6.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 264,124 kB
  • sloc: cpp: 113,426; ansic: 9,654; sh: 4,483; cs: 1,296; makefile: 407; yacc: 398; python: 382; lisp: 285; objc: 248; csh: 219; lex: 140; perl: 118; xml: 53; ruby: 36
file content (130 lines) | stat: -rw-r--r-- 4,404 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
.. _api_ref_calls:

=====
Calls
=====

.. _sq_call:

.. c:function:: SQRESULT sq_call(HSQUIRRELVM v, SQInteger params, SQBool retval, SQBool raiseerror)

    :param HSQUIRRELVM v: the target VM
    :param SQInteger params: number of parameters of the function
    :param SQBool retval: if true the function will push the return value in the stack
    :param SQBool raiseerror: if true, if a runtime error occurs during the execution of the call, the vm will invoke the error handler.
    :returns: a SQRESULT

calls a closure or a native closure. The function pops all the parameters and leave the closure in the stack; if retval is true the return value of the closure is pushed. If the execution of the function is suspended through sq_suspendvm(), the closure and the arguments will not be automatically popped from the stack.

When using to create an instance, push a dummy parameter to be filled with the newly-created instance for the constructor's 'this' parameter.



.. _sq_getcallee:

.. c:function:: SQRESULT sq_getcallee(HSQUIRRELVM v)

    :param HSQUIRRELVM v: the target VM
    :returns: a SQRESULT

push in the stack the currently running closure.





.. _sq_getlasterror:

.. c:function:: SQRESULT sq_getlasterror(HSQUIRRELVM v)

    :param HSQUIRRELVM v: the target VM
    :returns: a SQRESULT
    :remarks: the pushed error descriptor can be any valid squirrel type.

pushes the last error in the stack.





.. _sq_getlocal:

.. c:function:: const SQChar * sq_getlocal(HSQUIRRELVM v, SQUnsignedInteger level, SQUnsignedInteger nseq)

    :param HSQUIRRELVM v: the target VM
    :param SQUnsignedInteger level: the function index in the calls stack, 0 is the current function
    :param SQUnsignedInteger nseq: the index of the local variable in the stack frame (0 is 'this')
    :returns: the name of the local variable if a variable exists at the given level/seq otherwise NULL.

Returns the name of a local variable given stackframe and sequence in the stack and pushes is current value. Free variables are treated as local variables, by sq_getlocal(), and will be returned as they would be at the base of the stack, just before the real local variables.





.. _sq_reseterror:

.. c:function:: void sq_reseterror(HSQUIRRELVM v)

    :param HSQUIRRELVM v: the target VM

reset the last error in the virtual machine to null





.. _sq_resume:

.. c:function:: SQRESULT sq_resume(HSQUIRRELVM v, SQBool retval, SQBool raiseerror)

    :param HSQUIRRELVM v: the target VM
    :param SQBool retval: if true the function will push the return value in the stack
    :param SQBool raiseerror: if true, if a runtime error occurs during the execution of the call, the vm will invoke the error handler.
    :returns: a SQRESULT
    :remarks: if retval != 0 the return value of the generator is pushed.

resumes the generator at the top position of the stack.


.. _sq_tailcall:

.. c:function:: SQRESULT sq_tailcall(HSQUIRRELVM v, SQInteger nparams)

	:param HSQUIRRELVM v: the target VM
    :param SQInteger params: number of parameters of the function

	Calls a closure and removes the caller function from the call stack.
	This function must be invoke from a native closure and 
	he return value of sq_tailcall must be returned by the caller function(see example).
	
*.eg*

::

    SQInteger tailcall_something_example(HSQUIRRELVM v)
    {
		//push closure and parameters here
		... 
        return sq_tailcall(v,2);
    }
	
.. _sq_throwerror:

.. c:function:: SQRESULT sq_throwerror(HSQUIRRELVM v, const SQChar * err)

    :param HSQUIRRELVM v: the target VM
    :param const SQChar * err: the description of the error that has to be thrown
    :returns: the value that has to be returned by a native closure in order to throw an exception in the virtual machine.

sets the last error in the virtual machine and returns the value that has to be returned by a native closure in order to trigger an exception in the virtual machine.


.. _sq_throwobject:

.. c:function:: SQRESULT sq_throwobject(HSQUIRRELVM v)

    :param HSQUIRRELVM v: the target VM
    :returns: the value that has to be returned by a native closure in order to throw an exception in the virtual machine.

pops a value from the stack sets it as the last error in the virtual machine. Returns the value that has to be returned by a native closure in order to trigger an exception in the virtual machine (aka SQ_ERROR).