-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKRScript.cpp
111 lines (95 loc) · 2.92 KB
/
KRScript.cpp
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
#include "KRScript.h"
#include "tjs/tjsRandomGenerator.h"
TJS::tTJSBinaryStream* TVPCreateBinaryStreamForRead(const TJS::tTJSString& name,
const TJS::tTJSString& modestr) {
IStream* stream = TVPCreateIStream(ttstr(name.c_str()), TJS_BS_READ);
const tjs_char* o_ofs = TJS_strchr(modestr.c_str(), TJS_W('o'));
if (o_ofs != NULL) {
// seek to offset
o_ofs++;
tjs_char buf[256];
int i;
for (i = 0; i < 255; i++) {
if (o_ofs[i] >= TJS_W('0') && o_ofs[i] <= TJS_W('9'))
buf[i] = o_ofs[i];
else break;
}
buf[i] = 0;
tjs_uint64 ofs = ttstr(buf).AsInteger();
ULARGE_INTEGER cur;
stream->Seek(*((LARGE_INTEGER*)&ofs), SEEK_SET, &cur);
}
return (TJS::tTJSBinaryStream*)TVPCreateBinaryStreamAdapter(stream);
}
TJS::tTJSBinaryStream* TVPCreateBinaryStreamForWrite(const TJS::tTJSString& name,
const TJS::tTJSString& modestr) {
IStream* stream = TVPCreateIStream(ttstr(name.c_str()), TJS_BS_WRITE);
const tjs_char* o_ofs = TJS_strchr(modestr.c_str(), TJS_W('o'));
if (o_ofs != NULL) {
// seek to offset
o_ofs++;
tjs_char buf[256];
int i;
for (i = 0; i < 255; i++) {
if (o_ofs[i] >= TJS_W('0') && o_ofs[i] <= TJS_W('9'))
buf[i] = o_ofs[i];
else break;
}
buf[i] = 0;
tjs_uint64 ofs = ttstr(buf).AsInteger();
ULARGE_INTEGER cur;
stream->Seek(*((LARGE_INTEGER*)&ofs), SEEK_SET, &cur);
}
return (TJS::tTJSBinaryStream*)TVPCreateBinaryStreamAdapter(stream);
}
void initEngine() {
tTJSVariant val;
// Set eval expression mode
if (TVPGetCommandLine(TJS_W("-evalcontext"), &val))
{
ttstr str(val);
if (str == TJS_W("global"))
{
TJS::TJSEvalOperatorIsOnGlobal = true;
TJS::TJSWarnOnNonGlobalEvalOperator = true;
}
}
// Set igonre-prop compat mode
if (TVPGetCommandLine(TJS_W("-unaryaster"), &val))
{
ttstr str(val);
if (str == TJS_W("compat"))
{
TJS::TJSUnaryAsteriskIgnoresPropAccess = true;
}
}
// Set debug mode
if (TVPGetCommandLine(TJS_W("-debug"), &val))
{
ttstr str(val);
if (str == TJS_W("yes"))
{
TJS::TJSEnableDebugMode = true;
// if(TVPGetCommandLine(TJS_W("-warnrundelobj"), &val) )
// {
// str = val;
// if(str == TJS_W("yes"))
// {
TJS::TJSWarnOnExecutionOnDeletingObject = true;
// }
// }
}
}
// add kirikiriz
// set TJSGetRandomBits128
TJS::TJSGetRandomBits128 = TVPGetRandomBits128;
// script system initialization
// set console output gateway handler
//TVPScriptEngine->SetConsoleOutput(TVPGetTJS2ConsoleOutputGateway());
// set text stream functions
TJS::TJSCreateTextStreamForRead =(TJS::iTJSTextReadStream * (*)(const TJS::tTJSString &,const TJS::tTJSString&)) TVPCreateTextStreamForRead;
TJS::TJSCreateTextStreamForWrite = (TJS::iTJSTextWriteStream * (*)(const TJS::tTJSString&, const TJS::tTJSString&)) TVPCreateTextStreamForWrite;
// set binary stream functions
TJS::TJSCreateBinaryStreamForRead = TVPCreateBinaryStreamForRead;
TJS::TJSCreateBinaryStreamForWrite = TVPCreateBinaryStreamForWrite;
}