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
// tis.cpp : Defines the entry point for the console application.
//

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#include <stdio.h>
#include "aux-cvt.h"

#include "tiscript.hpp"

extern void InitUtilsPackage(tiscript::VM* x);
extern void InitMessageBoxClass(tiscript::VM* x);

// forward declarations
void usage();

int main(int argc, char* argv[])
{
if( argc < 2 )
usage();

tiscript::console cio;

const char* file_in = 0;
bool hypertext_mode = false;

tiscript::VM *vm = tiscript::create_vm();

tiscript::set_std_streams(vm, &cio,&cio,&cio);

//add our custom package Utils. see test_alert.js
InitUtilsPackage(vm);
InitMessageBoxClass(vm);

int n = 1;
if( stricmp("-ht", argv[1]) == 0 ) { hypertext_mode = true; ++n; }
if( n >= argc ) usage();
file_in = argv[n];

//ok, we've got here file name to execute
tiscript::file_utf8_istream *input = new tiscript::file_utf8_istream( aux::a2w(file_in) );
if(!input->is_valid())
{
printf("cannot open %s\n", file_in);
return -1;
}

// try to load and execute it.
tiscript::value retval = tiscript::eval(vm,tiscript::get_current_ns(vm), input, hypertext_mode);

tiscript::pinned arr(vm),func(vm);
// they are pinned because we will do allocations after it. GC can move elements.

// creating array
arr = tiscript::create_array(vm,3);
tiscript::set_elem( vm, arr, 0, tiscript::v_string(vm,L"first"));
tiscript::set_elem( vm, arr, 1, tiscript::v_string(vm,L"second"));
tiscript::set_elem( vm, arr, 2, tiscript::v_string(vm,L"third"));

tiscript::value args[1];
// calling function with the array
func = tiscript::get_prop(vm,tiscript::get_current_ns(vm),"printIt");
if( !tiscript::is_function(func) )
{
assert(false);
return -1;
}

args[0] = arr;
retval = tiscript::call(vm, tiscript::get_current_ns(vm), func, args, 1);

// creating object
tiscript::pinned obj(vm);
obj = tiscript::create_object(vm);
tiscript::set_prop( vm, obj, tiscript::v_symbol("first"), tiscript::v_int(1) );
tiscript::set_prop( vm, obj, tiscript::v_symbol("second"),tiscript::v_int(2) );
tiscript::set_prop( vm, obj, tiscript::v_symbol("third"), tiscript::v_int(3) );

// calling function with it.
args[0] = obj;
retval = tiscript::call(vm, tiscript::get_current_ns(vm), func, args, 1);

{
tiscript::value arg = tiscript::v_string(vm,L"{ok:true}");
retval = tiscript::call(vm, "generateForm", &arg, 1);
}

tiscript::value argv2[] =
{
tiscript::v_int( 2010 ),
tiscript::v_int( 12 ),
tiscript::v_int( 9 )
};

tiscript::value rt = tiscript::call( vm, tiscript::get_global_ns( vm ), "get_date_string", argv2, 3 );

std::wstring const date = tiscript::c_string( rt );

return 0;

}

void usage()
{
printf("Usage:\n\ttis.exe [-ht] filename\n\t -ht switch means interpret\n\tinput as hypertext with <%% script inclusion %%>.");
exit(-2);
}

Change log

r60 by andrew.fedoniouk on Dec 9, 2010   Diff
Added class file_utf8_istream to
sdk/include/tiscript-streams.hpp to
support input files in UTF8 encoding.


Go to: 
Project members, sign in to write a code review

Older revisions

r49 by andrew.fedoniouk on Sep 15, 2009   Diff
version 4.0.8.34. Sync with the Sciter
v.1.0.8.34.

1) various fixes.
2) multi-values:
...
r39 by andrew.fedoniouk on Feb 15, 2009   Diff
TIScript v.4.0, used in Sciter
v.1.0.7.24, http://www.terrainformatic
a.com/sciter/

New:
...
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: 3065 bytes, 109 lines
Powered by Google Project Hosting