-
Notifications
You must be signed in to change notification settings - Fork 6
/
Main.cpp
1086 lines (952 loc) · 23.7 KB
/
Main.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
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* copyright (c) 2007 Go Watanabe
*/
#ifndef NO_V2LINK
#include <windows.h>
#else
typedef unsigned long ULONG;
#endif
#include "tp_stub.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
using namespace std;
#define UNICODE_BOM (0xfeff)
static bool TVPUtf16ToUtf8( std::string& out, const tjs_char *in ) {
tjs_int len = TVPWideCharToUtf8String( in, NULL );
if( len < 0 ) return false;
char* buf = new char[len];
if( buf ) {
try {
len = TVPWideCharToUtf8String( in, buf );
if( len > 0 ) out.assign( buf, len );
delete[] buf;
} catch(...) {
delete[] buf;
throw;
}
}
return len > 0;
}
static bool TVPUtf16ToUtf8( std::string& out, const tjs_string& in ) {
return TVPUtf16ToUtf8(out, in.c_str());
}
// ----------------------------------------------------------------------
class IFileStorage {
IStream *in;
char buf[8192];
ULONG pos;
ULONG len;
bool eofFlag;
bool utf8;
public:
IFileStorage(tTJSVariantString *filename, bool utf8) : utf8(utf8) {
in = TVPCreateIStream(filename, TJS_BS_READ);
if(!in) {
TVPThrowExceptionMessage((ttstr(TJS_W("cannot open : ")) + *filename).c_str());
}
pos = 0;
len = 0;
eofFlag = false;
}
~IFileStorage() {
if (in) {
in->Release();
in = NULL;
}
}
int getc() {
if (pos < len) {
return buf[pos++];
} else {
if (!in || eofFlag) {
return EOF;
} else {
pos = 0;
if (in->Read(buf, sizeof buf, &len) == S_OK && len > 0) {
eofFlag = len < sizeof buf;
} else {
eofFlag = true;
len = 0;
}
return getc();
}
}
}
void ungetc() {
if (pos > 0) {
pos--;
}
}
bool eof() {
return pos >= len && eofFlag;
}
/**
* 改行チェック
*/
bool endOfLine(int c) {
bool eol = (c =='\r' || c == '\n');
if (c == '\r'){
c = getc();
if (!eof() && c != '\n') {
ungetc();
}
}
return eol;
}
bool addNextLine(ttstr &str) {
int c;
string mbline;
while ((c = getc()) != EOF && !endOfLine(c)) {
mbline += c;
}
int l = (int)mbline.length();
if (l > 0 || c != EOF) {
if (utf8) {
tjs_char *buf = new tjs_char[l + 1];
l = TVPUtf8ToWideCharString(mbline.data(), buf);
buf[l] = '\0';
str += buf;
delete[] buf;
} else {
str += tTJSString(mbline.c_str());
}
return true;
} else {
return false;
}
}
};
// -----------------------------------------------------------------
class JSONTextReadStream : public iTJSTextReadStream
{
public:
IFileStorage *Storage;
tjs_int codepage;
ttstr buf;
tjs_int pos;
JSONTextReadStream(tTJSVariantString *filename, tjs_int codepage) {
Storage = new IFileStorage(filename, codepage);
pos = 0;
}
~JSONTextReadStream(void) {
delete Storage;
}
virtual tjs_uint TJS_INTF_METHOD Read(tTJSString & targ, tjs_uint size) {
tjs_uint readSize = 0;
while (readSize < size) {
if (pos >= buf.length()) {
buf.Clear();
pos = 0;
if (! Storage->addNextLine(buf))
break;
}
tjs_uint n = min(tjs_uint(buf.length() - pos), size - readSize);
readSize += n;
while (n > 0) {
targ += buf[pos];
pos++;
n--;
}
}
return readSize;
}
virtual void TJS_INTF_METHOD Destruct() {
delete this;
}
};
// -----------------------------------------------------------------
class IReader {
public:
virtual int getc() = 0;
virtual void ungetc() = 0;
virtual void close() = 0;
bool isError;
/**
* コンストラクタ
*/
IReader() {
isError = false;
}
virtual ~IReader() {};
/**
* エラー処理
*/
void error(const tjs_char *msg) {
isError = true;
TVPAddLog(msg);
}
/**
* 行末まで読み飛ばす
*/
void toEOL() {
int c;
do {
c = getc();
} while (c != EOF && c != '\n' && c != '\r');
}
/**
* 空白とコメントを除去して次の文字を返す
*/
int next() {
for (;;) {
int c = getc();
if (c == '#') {
toEOL();
} else if (c == '/') {
switch (getc()) {
case '/':
toEOL();
break;
case '*':
for (;;) {
c = getc();
if (c == EOF) {
error(TJS_W("コメントが閉じていません"));
return EOF;
}
if (c == '*') {
if (getc() == '/') {
break;
}
ungetc();
}
}
break;
default:
ungetc();
return '/';
}
} else if (c != UNICODE_BOM && (c == EOF || c > ' ')) {
return c;
}
}
}
/**
* 指定された文字数分の文字列を取得
* @param str 文字列の格納先
* @param n 文字数
*/
void next(ttstr &str, int n) {
str = "";
while (n > 0) {
int c = getc();
if (c == EOF) {
break;
}
str += c;
n--;
}
}
void next(tjs_string &str, int n) {
str = TJS_W("");
while (n > 0) {
int c = getc();
if (c == EOF) {
break;
}
str += c;
n--;
}
}
void parseObject(tTJSVariant &var) {
// 辞書を生成
iTJSDispatch2 *dict = TJSCreateDictionaryObject();
var = tTJSVariant(dict, dict);
dict->Release();
int c;
for (;;) {
tTJSVariant key;
c = next();
if (c == EOF) {
error(TJS_W("オブジェクトは '}' で終了する必要があります"));
return;
} else if (c == '}') {
return;
} else if (c == ',' || c == ';') {
ungetc();
} else {
ungetc();
parse(key);
c = next();
if (c == '=') {
if (getc() != '>') {
ungetc();
}
} else if (c != ':') {
error(TJS_W("キーの後には ':' または '=' または '=>' が必要です"));
return;
}
// メンバ登録
tTJSVariant value;
parse(value);
dict->PropSet(TJS_MEMBERENSURE, key.GetString(), NULL, &value, dict);
}
switch (next()) {
case ';':
case ',':
break;
case '}':
return;
default:
error(TJS_W(" ',' または ';' または '}' が必要です"));
return;
}
}
}
void parseArray(tTJSVariant &var) {
// 配列を生成
iTJSDispatch2 *array = TJSCreateArrayObject();
var = tTJSVariant(array, array);
array->Release();
tjs_int cnt = 0;
for (;;) {
int ch = next();
switch (ch) {
case EOF:
error(TJS_W("配列は ']' で終了する必要があります"));
return;
case ']':
return;
case ',':
case ';':
{
ungetc();
// 空のカラムを登録
tTJSVariant value;
array->PropSetByNum(TJS_MEMBERENSURE, cnt++, &value, array);
}
break;
default:
ungetc();
tTJSVariant value;
parse(value);
array->PropSetByNum(TJS_MEMBERENSURE, cnt++, &value, array);
}
switch (next()) {
case ';':
case ',':
break;
case ']':
return;
default:
error(TJS_W(" ',' または ';' または ']' が必要です"));
return;
}
}
}
/**
* クオート文字列のパース
* @param quote クオート文字
* @param var 格納先
*/
void parseQuoteString(int quote, tTJSVariant &var) {
int c;
ttstr str;
for (;;) {
c = getc();
switch (c) {
case 0:
case '\n':
case '\r':
error(TJS_W("文字列が終端していません"));
return;
case '\\':
c = getc();
switch (c) {
case 'b':
str += '\b';
break;
case 'f':
str += '\f';
break;
case 't':
str += '\t';
break;
case 'r':
str += '\r';
break;
case 'n':
str += '\n';
break;
case 'u':
{
tjs_string work;
next(work, 4);
std::string out;
TVPUtf16ToUtf8(out, work);
str += (tjs_char)std::stol(out.c_str(), NULL, 16);
}
break;
case 'x' :
{
tjs_string work;
next(work, 2);
std::string out;
TVPUtf16ToUtf8(out, work);
str += (tjs_char)std::stol(out.c_str(), NULL, 16);
};
break;
default:
str += c;
}
break;
default:
if (c == quote) {
var = str;
return;
}
str += c;
}
}
}
/**
* 指定した文字が数値の1文字目の構成要素かどうか
*/
bool isNumberFirst(int ch) {
return (ch >= '0' && ch <= '9') || ch == '.' || ch == '-' || ch == '+';
}
/**
* 指定した文字が数値の構成要素かどうか
*/
bool isNumber(int ch) {
return (ch >= '0' && ch <= '9') || ch == '.' || ch == '-' || ch == '+' || ch == 'e' || ch == 'E';
}
/**
* 指定した文字が文字列の構成要素かどうか
*/
bool isString(int ch) {
return ch > 0x80 || ch > ' ' && TJS_strchr(TJS_W(",:]}/\\\"[{;=#"), ch) == NULL;
}
/**
* パースの実行
* @param var 結果格納先
*/
void parse(tTJSVariant &var) {
int ch = next();
switch (ch) {
case '"':
case '\'':
// クオート文字列
parseQuoteString(ch, var);
break;
case '{':
// オブジェクト
parseObject(var);
break;
case '[':
parseArray(var);
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '.':
case '-':
case '+':
{
// 数値
bool doubleValue = false;
tjs_string s;
while (isNumber(ch)) {
if (ch == '.') {
doubleValue = true; // ひどい処理だ(笑)
}
s += ch;
ch = getc();
}
ungetc();
std::string out;
TVPUtf16ToUtf8(out, s);
// 数値
if (doubleValue) {
double value = std::strtod(out.c_str(), NULL);
var = value;
} else {
tjs_int64 value = std::strtoll(out.c_str(), NULL, 10);
var = value;
}
}
break;
default:
if (ch >= 'a' && ch <= 'z') {
// 文字列を抽出
ttstr s;
while (ch >= 'a' && ch <= 'z') {
s += ch;
ch = getc();
}
ungetc();
// 識別子
if (s == TJS_W("true")) {
var = true;
} else if (s == TJS_W("false")) {
var = false;
} else if (s == TJS_W("null")) {
var.Clear();
} else if (s == TJS_W("void")) {
var.Clear();
} else {
ttstr msg = TJS_W("不明なキーワードです:");
msg += s;
error(msg.c_str());
}
} else {
ttstr msg = TJS_W("不明な文字です:");
error(msg.c_str());
}
}
}
};
class IFileReader : public IReader {
/// 入力バッファ
ttstr buf;
/// 入力ストリーム
iTJSTextReadStream *stream;
ULONG pos;
bool eofFlag;
public:
IFileReader(tTJSVariantString *filename, tjs_int codepage) {
stream = new JSONTextReadStream(filename, codepage);
pos = 0;
eofFlag = false;
}
virtual void close() {
if (stream) {
stream->Destruct();
stream = NULL;
}
}
~IFileReader() {
close();
}
int getc() {
if (pos < buf.length()) {
return buf.c_str()[pos++];
} else {
if (!stream || eofFlag) {
return EOF;
} else {
pos = 0;
buf.Clear();
eofFlag = stream->Read(buf, 1024) < 1024;
return getc();
}
}
}
void ungetc() {
if (pos > 0) {
pos--;
}
}
};
class IStringReader : public IReader {
ttstr dat;
const tjs_char *p;
ULONG length;
ULONG pos;
public:
IStringReader(const tjs_char *str) {
dat = str;
p = dat.c_str();
length = dat.length();
pos = 0;
}
void close() {
}
int getc() {
return pos < length ? p[pos++] : EOF;
}
void ungetc() {
if (pos > 0) {
pos--;
}
}
};
// -----------------------------------------------------------------
#include "Writer.hpp"
//---------------------------------------------------------------------------
// Array クラスメンバ
static iTJSDispatch2 *ArrayCountProp = NULL; // Array.count
// -----------------------------------------------------------------
static void
addMethod(iTJSDispatch2 *dispatch, const tjs_char *methodName, tTJSDispatch *method)
{
tTJSVariant var = tTJSVariant(method);
method->Release();
dispatch->PropSet(
TJS_MEMBERENSURE, // メンバがなかった場合には作成するようにするフラグ
methodName, // メンバ名 ( かならず TJS_W( ) で囲む )
NULL, // ヒント ( 本来はメンバ名のハッシュ値だが、NULL でもよい )
&var, // 登録する値
dispatch // コンテキスト
);
}
static void
delMethod(iTJSDispatch2 *dispatch, const tjs_char *methodName)
{
dispatch->DeleteMember(
0, // フラグ ( 0 でよい )
methodName, // メンバ名
NULL, // ヒント
dispatch // コンテキスト
);
}
static iTJSDispatch2*
getMember(iTJSDispatch2 *dispatch, const tjs_char *name)
{
tTJSVariant val;
if (TJS_FAILED(dispatch->PropGet(TJS_IGNOREPROP,
name,
NULL,
&val,
dispatch))) {
ttstr msg = TJS_W("can't get member:");
msg += name;
TVPThrowExceptionMessage(msg.c_str());
}
return val.AsObject();
}
// -----------------------------------------------------------------
static tjs_error eval(IReader &file, tTJSVariant *result)
{
tjs_error ret = TJS_S_OK;
if (result) {
file.parse(*result);
}
file.close();
if (file.isError) {
TVPThrowExceptionMessage(TJS_W("JSONファイル のパースに失敗しました"));
}
return ret;
}
//---------------------------------------------------------------------------
/**
* JSON を文字列から読み取る
* @param text JSON の文字列表現
*/
class tEvalJSON : public tTJSDispatch
{
protected:
public:
tjs_error TJS_INTF_METHOD FuncCall(
tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
tTJSVariant *result,
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) {
if (membername) return TJS_E_MEMBERNOTFOUND;
if (numparams < 1) return TJS_E_BADPARAMCOUNT;
IStringReader reader(param[0]->GetString());
eval(reader, result);
return TJS_S_OK;
}
};
/**
* JSON をファイルから読み取る
* @param filename ファイル名
*/
class tEvalJSONStorage : public tTJSDispatch
{
protected:
public:
tjs_error TJS_INTF_METHOD FuncCall(
tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
tTJSVariant *result,
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) {
if (membername) return TJS_E_MEMBERNOTFOUND;
if (numparams < 1) return TJS_E_BADPARAMCOUNT;
tTJSVariantString *filename = param[0]->AsStringNoAddRef();
bool utf8 = numparams >= 2 ? (int*)param[1] != 0 : false;
IFileReader reader(filename, utf8);
eval(reader, result);
return TJS_S_OK;
}
};
static void
quoteString(const tjs_char *str, IWriter *writer)
{
if (str) {
writer->write((tjs_char)'"');
const tjs_char *p = str;
int ch;
while ((ch = *p++)) {
if (ch == '"') {
writer->write(TJS_W("\\\""));
} else if (ch == '\\') {
writer->write(TJS_W("\\\\"));
} else if (ch == 0x08) {
writer->write(TJS_W("\\b"));
} else if (ch == 0x0c) {
writer->write(TJS_W("\\f"));
} else if (ch == 0x0a) {
writer->write(TJS_W("\\n"));
} else if (ch == 0x0d) {
writer->write(TJS_W("\\r"));
} else if (ch == 0x09) {
writer->write(TJS_W("\\t"));
} else if (ch < 0x20) {
char buf[256];
std::snprintf(buf, 255, "\\u%04x", ch);
tjs_char wbuf[256];
size_t l = TVPUtf8ToWideCharString(buf, wbuf);
wbuf[l] = (tjs_char)'\0';
writer->write(wbuf);
} else {
writer->write((tjs_char)ch);
}
}
writer->write((tjs_char)'"');
} else {
writer->write(TJS_W("\"\""));
}
}
static void getVariantString(tTJSVariant &var, IWriter *writer);
/**
* 辞書の内容表示用の呼び出しロジック
*/
class DictMemberDispCaller : public tTJSDispatch /** EnumMembers 用 */
{
protected:
IWriter *writer;
bool first;
public:
DictMemberDispCaller(IWriter *writer) : writer(writer) { first = true; };
virtual tjs_error TJS_INTF_METHOD FuncCall( // function invocation
tjs_uint32 flag, // calling flag
const tjs_char * membername,// member name ( NULL for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
tTJSVariant *result, // result
tjs_int numparams, // number of parameters
tTJSVariant **param, // parameters
iTJSDispatch2 *objthis // object as "this"
) {
if (numparams > 1) {
tTVInteger flag = param[1]->AsInteger();
if (!(flag & TJS_HIDDENMEMBER)) {
if (first) {
first = false;
} else {
writer->write((tjs_char)',');
writer->newline();
}
quoteString(param[0]->GetString(), writer);
writer->write((tjs_char)':');
getVariantString(*param[2], writer);
}
}
if (result) {
*result = true;
}
return TJS_S_OK;
}
};
static void getDictString(iTJSDispatch2 *dict, IWriter *writer)
{
writer->write((tjs_char)'{');
writer->addIndent();
DictMemberDispCaller *caller = new DictMemberDispCaller(writer);
tTJSVariantClosure closure(caller);
dict->EnumMembers(TJS_IGNOREPROP, &closure, dict);
caller->Release();
writer->delIndent();
writer->write((tjs_char)'}');
}
static void getArrayString(iTJSDispatch2 *array, IWriter *writer)
{
writer->write((tjs_char)'[');
writer->addIndent();
tjs_int count = 0;
{
tTJSVariant result;
if (TJS_SUCCEEDED(ArrayCountProp->PropGet(0, NULL, NULL, &result, array))) {
count = result.AsInteger();
}
}
for (tjs_int i=0; i<count; i++) {
if (i != 0) {
writer->write((tjs_char)',');
writer->newline();
}
tTJSVariant result;
if (array->PropGetByNum(TJS_IGNOREPROP, i, &result, array) == TJS_S_OK) {
getVariantString(result, writer);
}
}
writer->delIndent();
writer->write((tjs_char)']');
}
static void
getVariantString(tTJSVariant &var, IWriter *writer)
{
switch(var.Type()) {
case tvtVoid:
writer->write(TJS_W("null"));
break;
case tvtObject:
{
iTJSDispatch2 *obj = var.AsObjectNoAddRef();
if (obj == NULL) {
writer->write(TJS_W("null"));
} else if (obj->IsInstanceOf(TJS_IGNOREPROP,NULL,NULL,TJS_W("Array"),obj) == TJS_S_TRUE) {
getArrayString(obj, writer);
} else {
getDictString(obj, writer);
}
}
break;
case tvtString:
quoteString(var.GetString(), writer);
break;
case tvtInteger:
writer->write((tTVInteger)var);
break;
case tvtReal: {
ttstr str = var;
// delete top '+' of number.
if (str[0] == L'+') {
ttstr src = str;
str = src.c_str() + 1;
}
writer->write(str.c_str());
break;
}
default:
writer->write(TJS_W("null"));
break;
};
}
/**
*
*/
class tSaveJSON : public tTJSDispatch
{
protected:
public:
tjs_error TJS_INTF_METHOD FuncCall(
tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
tTJSVariant *result,
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) {
if (numparams < 2) return TJS_E_BADPARAMCOUNT;
IFileWriter writer(param[0]->GetString(),
numparams > 2 ? (int)*param[2] != 0 : false,
numparams > 3 ? (int)*param[3] : 0);
getVariantString(*param[1], &writer);
return TJS_S_OK;
}
};
/**
*
*/
class tToJSONString : public tTJSDispatch
{
protected:
public:
tjs_error TJS_INTF_METHOD FuncCall(
tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
tTJSVariant *result,
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) {
if (numparams < 1) return TJS_E_BADPARAMCOUNT;
if (result) {
IStringWriter writer(numparams > 1 ? (tjs_int)*param[1] : 0);
getVariantString(*param[0], &writer);
*result = writer.buf;
}
return TJS_S_OK;
}
};
void json_init()
{
// Arary クラスメンバー取得
{
tTJSVariant varScripts;
TVPExecuteExpression(TJS_W("Array"), &varScripts);
iTJSDispatch2 *dispatch = varScripts.AsObjectNoAddRef();
// メンバ取得
ArrayCountProp = getMember(dispatch, TJS_W("count"));
}
{
tTJSVariant varScripts;
TVPExecuteExpression(TJS_W("Scripts"), &varScripts);
iTJSDispatch2 *dispatch = varScripts.AsObjectNoAddRef();
if (dispatch) {
addMethod(dispatch, TJS_W("evalJSON"), new tEvalJSON());
addMethod(dispatch, TJS_W("evalJSONStorage"), new tEvalJSONStorage());
addMethod(dispatch, TJS_W("saveJSON"), new tSaveJSON());
addMethod(dispatch, TJS_W("toJSONString"), new tToJSONString());
}
}
}