author | glx |
Sun, 15 Jun 2008 22:56:43 +0000 | |
branch | noai |
changeset 10973 | 8577bc56132c |
parent 10887 | 5c81038449f2 |
child 11098 | 37d15a8951b8 |
permissions | -rw-r--r-- |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
1 |
/* $Id$ */ |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
2 |
|
9422
33efcc5f1b09
(svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents:
9404
diff
changeset
|
3 |
/** @file squirrel.hpp defines the Squirrel class */ |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
4 |
|
9422
33efcc5f1b09
(svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents:
9404
diff
changeset
|
5 |
#ifndef SQUIRREL_HPP |
33efcc5f1b09
(svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents:
9404
diff
changeset
|
6 |
#define SQUIRREL_HPP |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
7 |
|
9422
33efcc5f1b09
(svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents:
9404
diff
changeset
|
8 |
class Squirrel { |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
9 |
private: |
9789
33d3214a2fce
(svn r12286) [NoAI] -Fix (r12277): restore compilation with _UNICODE
glx
parents:
9782
diff
changeset
|
10 |
typedef void (SQPrintFunc)(bool error_msg, const SQChar *message); |
9782
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
11 |
|
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
12 |
HSQUIRRELVM vm; ///< The VirtualMachine instnace for squirrel |
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
13 |
void *global_pointer; ///< Can be set by who ever initializes Squirrel |
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
14 |
SQPrintFunc *print_func; ///< Points to either NULL, or a custom print handler |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
15 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
16 |
/** |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
17 |
* The internal RunError handler. It looks up the real error and calls RunError with it. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
18 |
*/ |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
19 |
static SQInteger _RunError(HSQUIRRELVM vm); |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
20 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
21 |
protected: |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
22 |
/** |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
23 |
* The CompileError handler. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
24 |
*/ |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
25 |
static void CompileError(HSQUIRRELVM vm, const SQChar *desc, const SQChar *source, SQInteger line, SQInteger column); |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
26 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
27 |
/** |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
28 |
* The RunError handler. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
29 |
*/ |
9789
33d3214a2fce
(svn r12286) [NoAI] -Fix (r12277): restore compilation with _UNICODE
glx
parents:
9782
diff
changeset
|
30 |
static void RunError(HSQUIRRELVM vm, const SQChar *error); |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
31 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
32 |
/** |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
33 |
* If a user runs 'print' inside a script, this function gets the params. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
34 |
*/ |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
35 |
static void PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...); |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
36 |
|
9576
d650eb70a8d0
(svn r9593) [NoAI] -Add: on runtime-error, print the complete stack, so the user can see where it went wrong
truelight
parents:
9539
diff
changeset
|
37 |
/** |
d650eb70a8d0
(svn r9593) [NoAI] -Add: on runtime-error, print the complete stack, so the user can see where it went wrong
truelight
parents:
9539
diff
changeset
|
38 |
* If an error has to be print, this function is called. |
d650eb70a8d0
(svn r9593) [NoAI] -Add: on runtime-error, print the complete stack, so the user can see where it went wrong
truelight
parents:
9539
diff
changeset
|
39 |
*/ |
d650eb70a8d0
(svn r9593) [NoAI] -Add: on runtime-error, print the complete stack, so the user can see where it went wrong
truelight
parents:
9539
diff
changeset
|
40 |
static void ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...); |
d650eb70a8d0
(svn r9593) [NoAI] -Add: on runtime-error, print the complete stack, so the user can see where it went wrong
truelight
parents:
9539
diff
changeset
|
41 |
|
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
42 |
public: |
9422
33efcc5f1b09
(svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents:
9404
diff
changeset
|
43 |
Squirrel(); |
33efcc5f1b09
(svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents:
9404
diff
changeset
|
44 |
~Squirrel(); |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
45 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
46 |
/** |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
47 |
* Load a script. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
48 |
* @param script The full script-name to load. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
49 |
* @return False if loading failed. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
50 |
*/ |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
51 |
bool LoadScript(const char *script); |
10887
5c81038449f2
(svn r13438) [NoAI] -Fix: sq_pop when needed, to make sure the stack keeps as clean as possible
truebrain
parents:
10873
diff
changeset
|
52 |
static bool LoadScript(HSQUIRRELVM vm, const char *script, bool in_root = true); |
10649
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
9813
diff
changeset
|
53 |
|
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
9813
diff
changeset
|
54 |
/** |
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
9813
diff
changeset
|
55 |
* Load a file to a given VM. |
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
9813
diff
changeset
|
56 |
*/ |
9034b80fdbdb
(svn r13193) [NoAI] -Add: allow AIs to be packed in a .tar. one AI per tar, always in a subdir. It looks for main.nut in the first dir it finds in the archive
truebrain
parents:
9813
diff
changeset
|
57 |
static SQRESULT LoadFile(HSQUIRRELVM vm, const char *filename, SQBool printerror); |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
58 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
59 |
/** |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
60 |
* Adds a function to the stack. Depending on the current state this means |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
61 |
* either a method or a global function. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
62 |
*/ |
9539
7416d0694d3a
(svn r9461) [NoAI] -Add: allow to set the amount of params that SQ should expect in the SQ define lines. Script to automated this are coming up next.
truelight
parents:
9525
diff
changeset
|
63 |
void AddMethod(const char *method_name, SQFUNCTION proc, uint nparam = 0, const char *params = NULL, void *userdata = NULL, int size = 0); |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
64 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
65 |
/** |
9525
1d6c509b56ee
(svn r9445) [NoAI] -Change: changed from sq_createslot to sq_newslot (first is deprecated)
truelight
parents:
9435
diff
changeset
|
66 |
* Adds a const to the stack. Depending on the current state this means |
1d6c509b56ee
(svn r9445) [NoAI] -Change: changed from sq_createslot to sq_newslot (first is deprecated)
truelight
parents:
9435
diff
changeset
|
67 |
* either a const to a class or to the global space. |
1d6c509b56ee
(svn r9445) [NoAI] -Change: changed from sq_createslot to sq_newslot (first is deprecated)
truelight
parents:
9435
diff
changeset
|
68 |
*/ |
1d6c509b56ee
(svn r9445) [NoAI] -Change: changed from sq_createslot to sq_newslot (first is deprecated)
truelight
parents:
9435
diff
changeset
|
69 |
void AddConst(const char *var_name, int value); |
1d6c509b56ee
(svn r9445) [NoAI] -Change: changed from sq_createslot to sq_newslot (first is deprecated)
truelight
parents:
9435
diff
changeset
|
70 |
|
1d6c509b56ee
(svn r9445) [NoAI] -Change: changed from sq_createslot to sq_newslot (first is deprecated)
truelight
parents:
9435
diff
changeset
|
71 |
/** |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
72 |
* Adds a class to the global scope. Make sure to call AddClassEnd when you |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
73 |
* are done adding methods. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
74 |
*/ |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
75 |
void AddClassBegin(const char *class_name); |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
76 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
77 |
/** |
9588
01b2435c977b
(svn r9618) [NoAI] -Add: allow an extra param for PreRegister to register classes as extends of others
truelight
parents:
9576
diff
changeset
|
78 |
* Adds a class to the global scope, extending 'parent_class'. |
01b2435c977b
(svn r9618) [NoAI] -Add: allow an extra param for PreRegister to register classes as extends of others
truelight
parents:
9576
diff
changeset
|
79 |
* Make sure to call AddClassEnd when you are done adding methods. |
01b2435c977b
(svn r9618) [NoAI] -Add: allow an extra param for PreRegister to register classes as extends of others
truelight
parents:
9576
diff
changeset
|
80 |
*/ |
01b2435c977b
(svn r9618) [NoAI] -Add: allow an extra param for PreRegister to register classes as extends of others
truelight
parents:
9576
diff
changeset
|
81 |
void AddClassBegin(const char *class_name, const char *parent_class); |
01b2435c977b
(svn r9618) [NoAI] -Add: allow an extra param for PreRegister to register classes as extends of others
truelight
parents:
9576
diff
changeset
|
82 |
|
01b2435c977b
(svn r9618) [NoAI] -Add: allow an extra param for PreRegister to register classes as extends of others
truelight
parents:
9576
diff
changeset
|
83 |
/** |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
84 |
* Finishes adding a class to the global scope. If this isn't called, no |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
85 |
* class is really created. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
86 |
*/ |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
87 |
void AddClassEnd(); |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
88 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
89 |
/** |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
90 |
* Call a method of an instance, in various flavors. |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
91 |
*/ |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
92 |
void CallMethod(HSQOBJECT instance, const char *method_name, HSQOBJECT *ret); |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
93 |
void CallMethod(HSQOBJECT instance, const char *method_name) { this->CallMethod(instance, method_name, NULL); } |
10873
89076fb5bd06
(svn r13424) [NoAI] -Codechange: strdup strings returned by Squirrel when it's called from openttd.
glx
parents:
10650
diff
changeset
|
94 |
const char *CallStringMethodStrdup(HSQOBJECT instance, const char *method_name) { HSQOBJECT ret; this->CallMethod(instance, method_name, &ret); return strdup(ObjectToString(&ret)); } |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
95 |
int CallIntegerMethod(HSQOBJECT instance, const char *method_name) { HSQOBJECT ret; this->CallMethod(instance, method_name, &ret); return ObjectToInteger(&ret); } |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
96 |
|
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
97 |
/** |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
98 |
* Check if a method exists in an instance. |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
99 |
*/ |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
100 |
bool MethodExists(HSQOBJECT instance, const char *method_name); |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
101 |
|
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
102 |
/** |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
103 |
* Creates a class instance. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
104 |
* @param class_name The name of the class of which we create an instance. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
105 |
* @param real_instance The instance to the real class, if it represents a real class. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
106 |
* @param instance Returning value with the pointer to the instance. |
9674
15f7b310b6cf
(svn r10613) [NoAI] -Add r10612: give release-hook for return values of classes for which SQ creates a temporary holder so they are free'd when SQ does
truelight
parents:
9673
diff
changeset
|
107 |
* @param release_hook Optional param to give a release hook. |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
108 |
* @return False if creating failed. |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
109 |
*/ |
9674
15f7b310b6cf
(svn r10613) [NoAI] -Add r10612: give release-hook for return values of classes for which SQ creates a temporary holder so they are free'd when SQ does
truelight
parents:
9673
diff
changeset
|
110 |
static bool CreateClassInstanceVM(HSQUIRRELVM vm, const char *class_name, void *real_instance, HSQOBJECT *instance, SQRELEASEHOOK release_hook); |
9673
ee4f133c84ec
(svn r10612) [NoAI] -Add: allow a class as return value; pack the result in a SQ instance and it should work perfectly
truelight
parents:
9588
diff
changeset
|
111 |
|
ee4f133c84ec
(svn r10612) [NoAI] -Add: allow a class as return value; pack the result in a SQ instance and it should work perfectly
truelight
parents:
9588
diff
changeset
|
112 |
/** |
ee4f133c84ec
(svn r10612) [NoAI] -Add: allow a class as return value; pack the result in a SQ instance and it should work perfectly
truelight
parents:
9588
diff
changeset
|
113 |
* Exactly the same as CreateClassInstanceVM, only callable without instance of Squirrel. |
ee4f133c84ec
(svn r10612) [NoAI] -Add: allow a class as return value; pack the result in a SQ instance and it should work perfectly
truelight
parents:
9588
diff
changeset
|
114 |
*/ |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
115 |
bool CreateClassInstance(const char *class_name, void *real_instance, HSQOBJECT *instance); |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
116 |
|
9394
796c684ca5b6
(svn r9186) [NoAI] -Documentation: forgot to document GetInstance()
truelight
parents:
9393
diff
changeset
|
117 |
/** |
796c684ca5b6
(svn r9186) [NoAI] -Documentation: forgot to document GetInstance()
truelight
parents:
9393
diff
changeset
|
118 |
* Get the real-instance pointer. |
796c684ca5b6
(svn r9186) [NoAI] -Documentation: forgot to document GetInstance()
truelight
parents:
9393
diff
changeset
|
119 |
* @note This will only work just after a function-call from within Squirrel |
796c684ca5b6
(svn r9186) [NoAI] -Documentation: forgot to document GetInstance()
truelight
parents:
9393
diff
changeset
|
120 |
* to your C++ function. |
796c684ca5b6
(svn r9186) [NoAI] -Documentation: forgot to document GetInstance()
truelight
parents:
9393
diff
changeset
|
121 |
*/ |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
122 |
static bool GetRealInstance(HSQUIRRELVM vm, SQUserPointer *ptr) { return SQ_SUCCEEDED(sq_getinstanceup(vm, 1, ptr, 0)); } |
9394
796c684ca5b6
(svn r9186) [NoAI] -Documentation: forgot to document GetInstance()
truelight
parents:
9393
diff
changeset
|
123 |
|
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
124 |
/** |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
125 |
* Get the Squirrel-instance pointer. |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
126 |
* @note This will only work just after a function-call from within Squirrel |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
127 |
* to your C++ function. |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
128 |
*/ |
10650
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
129 |
static bool GetInstance(HSQUIRRELVM vm, HSQOBJECT *ptr, int pos = 1) { sq_getclass(vm, pos); sq_getstackobj(vm, pos, ptr); sq_pop(vm, 1); return true; } |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
130 |
|
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
131 |
/** |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
132 |
* Convert a Squirrel-object to a string. |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
133 |
*/ |
9435
9dad22394553
(svn r9245) [NoAI] -Fix: allow compilation with _UNICODE
glx
parents:
9422
diff
changeset
|
134 |
static const char *ObjectToString(HSQOBJECT *ptr) { return FS2OTTD(sq_objtostring(ptr)); } |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
135 |
|
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
136 |
/** |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
137 |
* Convert a Squirrel-object to an integer. |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
138 |
*/ |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
139 |
static int ObjectToInteger(HSQOBJECT *ptr) { return sq_objtointeger(ptr); } |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
140 |
|
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
141 |
/** |
9782
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
142 |
* Sets a pointer in the VM that is reachable from where ever you are in SQ. |
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
143 |
* Useful to keep track of the main instance. |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
144 |
*/ |
9782
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
145 |
void SetGlobalPointer(void *ptr) { this->global_pointer = ptr; } |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
146 |
|
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
147 |
/** |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
148 |
* Get the pointer as set by SetGlobalPointer. |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
149 |
*/ |
9782
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
150 |
static void *GetGlobalPointer(HSQUIRRELVM vm) { return ((Squirrel *)sq_getforeignptr(vm))->global_pointer; } |
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
151 |
|
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
152 |
/** |
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
153 |
* Set a custom print function, so you can handle outputs from SQ yourself. |
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
154 |
*/ |
e8d8d8894f23
(svn r12277) [NoAI] -Change: overlay GlobalPointer with local instance access and create sub-node to contain data
truebrain
parents:
9674
diff
changeset
|
155 |
void SetPrintFunction(SQPrintFunc *func) { this->print_func = func; } |
9404
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
156 |
|
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
157 |
/** |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
158 |
* Throw a Squirrel error that will be nicely displayed to the user. |
ef9e171617a3
(svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents:
9399
diff
changeset
|
159 |
*/ |
9435
9dad22394553
(svn r9245) [NoAI] -Fix: allow compilation with _UNICODE
glx
parents:
9422
diff
changeset
|
160 |
void ThrowError(const char *error) { sq_throwerror(this->vm, OTTD2FS(error)); } |
10650
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
161 |
|
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
162 |
/** |
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
163 |
* Release a SQ object. |
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
164 |
*/ |
30fc5395b1b8
(svn r13194) [NoAI] -Change [API CHANGE]: split 'main.nut' in 'info.nut' and 'main.nut'. The first contains the information about the AI, the second the AI. This avoid several problems we had. It also speeds up OpenTTD start-up.
truebrain
parents:
10649
diff
changeset
|
165 |
void ReleaseObject(HSQOBJECT *ptr) { sq_release(this->vm, ptr); } |
9393
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
166 |
}; |
04bd925b9069
(svn r9185) [NoAI] -Codechange: split up the squirrel code so we have SquirrelCore
truelight
parents:
diff
changeset
|
167 |
|
9422
33efcc5f1b09
(svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents:
9404
diff
changeset
|
168 |
#endif /* SQUIRREL_HPP */ |