My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
// native_classes.cpp
//
// implementation of custom package Utils and class MessageBox
//
// see: script sample alert_test.js
//

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include "aux-cvt.h"
#include "tiscript.hpp"

#include <string>

using namespace tiscript;

// custom package Utils, it is just a class without ctor

// method Utils.alert(string)
value Utils_alert(VM *vm)
{
std::wstring msg;
try
{
args(vm)
>> args::skip // this is class method (a.k.a. static) so 'this' is the class here.
>> args::skip // skip 'super'
>> msg;
}
catch (args::error &e) { throw_error(vm, e.msg()); return v_undefined(); }

::MessageBoxW(NULL,msg.c_str(),L"script alert", MB_OK | MB_ICONEXCLAMATION);

return v_undefined();
};

// method list of package Utils
static method_def Utils_methods[] =
{
method_def("alert", &Utils_alert),
method_def() // zero terminated, sic!
};

struct tiscript_class_def Utils =
{
"Utils",
Utils_methods,
};

void InitUtilsPackage(VM *vm)
{
define_class(vm,&Utils);
}

// custom object MessageBox

struct MessageBox_instance
{
std::wstring caption;
std::wstring message;
};

//MessageBox.this( [message[, caption]] ) - constructor
value TISAPI MessageBox_constructor( VM* vm )
{
std::wstring msg;
std::wstring cap;
pinned self;

try
{
args(vm)
>> self // this.
>> args::skip // skip 'super'
>> args::optional // rest of arguments are optional
>> msg
>> cap;
}
catch (args::error &e) { throw_error(vm, e.msg()); return v_undefined(); }

MessageBox_instance* pinst = new MessageBox_instance;

pinst->message = msg;
pinst->caption = cap;

set_native_data(self,pinst);
return self;
}

inline MessageBox_instance * self_data(value obj)
{
return (MessageBox_instance*) get_native_data(obj);
}


//MessageBox.show( )
value TISAPI MessageBox_show( VM* vm )
{
pinned self;
try
{
args(vm)
>> self // this.
>> args::skip; // skip 'super'
}
catch (args::error &e) { throw_error(vm, e.msg()); return v_undefined(); }

MessageBox_instance* pinst = self_data(self);
if( pinst )
::MessageBoxW(NULL, pinst->message.c_str(), pinst->caption.c_str(), MB_OK | MB_ICONEXCLAMATION);
else
assert(false);
return v_undefined();
}

// MessageBox.caption property
value TISAPI MessageBox_get_caption(VM* vm,value self)
{
MessageBox_instance* pinst = self_data(self);
if( pinst )
return v_string(vm,pinst->caption.c_str());
return v_null();
}

// MessageBox.caption property
void TISAPI MessageBox_set_caption( VM* vm,value self, value val)
{
MessageBox_instance* pinst = self_data(self);
if( !pinst )
return;

if( ! is_string(val) )
{
throw_error(vm, L"Only string please!");
return;
}
pinst->caption = c_string(val);
}

// MessageBox.message property
value TISAPI MessageBox_get_message(VM* vm, value self)
{
MessageBox_instance* pinst = self_data(self);
if( pinst )
return v_string(vm,pinst->message.c_str());
return v_null();
}

// MessageBox.message property
void TISAPI MessageBox_set_message( VM* vm, value self, value val)
{
MessageBox_instance* pinst = self_data(self);
if( !pinst )
return;

if( ! is_string(val) )
throw_error(vm, L"Only string please!");

pinst->message = c_string(val);
}

void TISAPI MessageBox_finalizer(VM* vm, value self)
{
MessageBox_instance* pinst = self_data(self);
if( !pinst )
return;
set_native_data(self,0);
delete pinst;
}

// method list of package Utils
static method_def MessageBox_methods[] =
{
method_def("this", MessageBox_constructor),
method_def("show", MessageBox_show),
method_def() // zero terminated, sic!
};

// method list of package Utils
static prop_def MessageBox_properties[] =
{
prop_def( "caption", &MessageBox_get_caption, &MessageBox_set_caption ),
prop_def( "message", &MessageBox_get_message, &MessageBox_set_message ),
prop_def( ) // zero terminated, sic!
};

struct tiscript_class_def MessageBoxClass =
{
"MessageBox",
MessageBox_methods,
MessageBox_properties,
0,0,0,
MessageBox_finalizer
};

void InitMessageBoxClass(VM* vm)
{
define_class(vm,&MessageBoxClass);
}

Change log

r39 by andrew.fedoniouk on Feb 15, 2009   Diff
TIScript v.4.0, used in Sciter v.1.0.7.24,
http://www.terrainformatica.com/sciter/

New:
  1) namespaces and classes. See : http://
www.terrainformatica.com/wiki/tiscript/cla
sses
  2) decorators, see: http://www.terrainfo
rmatica.com/wiki/tiscript/decorators and
http://www.terrainformatica.com/?p=108
  3) property undefined() a.k.a. virtual
properties, see: http://www.terrainformati
...
Go to: 
Project members, sign in to write a code review

Older revisions

r38 by andrew.fedoniouk on Sep 4, 2008   Diff
Missed files from /SDK folder has been
added.
All revisions of this file

File info

Size: 4508 bytes, 200 lines
Powered by Google Project Hosting