-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtp_stub.h
10634 lines (9758 loc) · 458 KB
/
tp_stub.h
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
/*
TVP2 ( T Visual Presenter 2 ) A script authoring tool
Copyright (C) 2000-2009 W.Dee <[email protected]> and contributors
See details of license at "license.txt"
*/
/* This file is always generated by makestub.pl . */
/* Modification by hand will be lost. */
#ifndef __TP_STUB_H__
#define __TP_STUB_H__
#ifndef __cplusplus
#error Sorry, currently tp_stub.h can only be used in C++ mode.
#endif
#ifndef _WIN32
#error Sorry, currently tp_stub.h can only be used in Win32 VC++ or Borland compilers.
#endif
#include <windows.h>
typedef __int8 tjs_int8;
typedef unsigned __int8 tjs_uint8;
typedef __int16 tjs_int16;
typedef unsigned __int16 tjs_uint16;
typedef __int32 tjs_int32;
typedef unsigned __int32 tjs_uint32;
typedef __int64 tjs_int64;
typedef unsigned __int64 tjs_uint64;
typedef int tjs_int; /* at least 32bits */
typedef unsigned int tjs_uint; /* at least 32bits */
#ifdef __cplusplus
typedef wchar_t tjs_char;
#else
typedef unsigned short tjs_char;
#endif
typedef char tjs_nchar;
typedef double tjs_real;
#define TJS_HOST_IS_BIG_ENDIAN 0
#define TJS_HOST_IS_LITTLE_ENDIAN 1
#ifndef TJS_INTF_METHOD
#define TJS_INTF_METHOD __cdecl
/* TJS_INTF_METHOD is "cdecl" (by default)
since TJS2 2.4.14 (kirikir2 2.25 beta 1) */
#endif
#define TJS_USERENTRY __cdecl
#define TJS_I64_VAL(x) ((tjs_int64)(x##i64))
#define TJS_UI64_VAL(x) ((tjs_uint64)(x##i64))
#define TJS_W(X) L##X
#define TJS_N(X) X
typedef tjs_int32 tjs_error;
typedef tjs_int64 tTVInteger;
typedef tjs_real tTVReal;
/* IEEE double manipulation support
(TJS requires IEEE double(64-bit float) native support on machine or C++ compiler) */
/*
63 62 52 51 0
+-+-----------+---------------------------+
|s| exp | significand |
+-+-----------+---------------------------+
s = sign, negative if this is 1, otherwise positive.
*/
/* double related constants */
#define TJS_IEEE_D_EXP_MAX 1023
#define TJS_IEEE_D_EXP_MIN -1022
#define TJS_IEEE_D_SIGNIFICAND_BITS 52
#define TJS_IEEE_D_EXP_BIAS 1023
/* component extraction */
#define TJS_IEEE_D_SIGN_MASK (TJS_UI64_VAL(0x8000000000000000))
#define TJS_IEEE_D_EXP_MASK (TJS_UI64_VAL(0x7ff0000000000000))
#define TJS_IEEE_D_SIGNIFICAND_MASK (TJS_UI64_VAL(0x000fffffffffffff))
#define TJS_IEEE_D_SIGNIFICAND_MSB_MASK (TJS_UI64_VAL(0x0008000000000000))
#define TJS_IEEE_D_GET_SIGN(x) ((bool)(x & TJS_IEEE_D_SIGN_MASK))
#define TJS_IEEE_D_GET_EXP(x) ((tjs_int)(((x & TJS_IEEE_D_EXP_MASK) >> \
TJS_IEEE_D_SIGNIFICAND_BITS) - TJS_IEEE_D_EXP_BIAS))
#define TJS_IEEE_D_GET_SIGNIFICAND(x) (x & TJS_IEEE_D_SIGNIFICAND_MASK)
/* component composition */
#define TJS_IEEE_D_MAKE_SIGN(x) ((x)?TJS_UI64_VAL(0x8000000000000000):TJS_UI64_VAL(0))
#define TJS_IEEE_D_MAKE_EXP(x) ((tjs_uint64)(x + TJS_IEEE_D_EXP_BIAS) << 52)
#define TJS_IEEE_D_MAKE_SIGNIFICAND(x) ((tjs_uint64)(x))
/* special expression */
/* (quiet) NaN */
#define TJS_IEEE_D_P_NaN (tjs_uint64)(TJS_IEEE_D_EXP_MASK|TJS_IEEE_D_SIGNIFICAND_MSB_MASK)
#define TJS_IEEE_D_N_NaN (tjs_uint64)(TJS_IEEE_D_SIGN_MASK|TJS_IEEE_D_P_NaN)
/* infinite */
#define TJS_IEEE_D_P_INF (tjs_uint64)(TJS_IEEE_D_EXP_MASK)
#define TJS_IEEE_D_N_INF (tjs_uint64)(TJS_IEEE_D_SIGN_MASK|TJS_IEEE_D_P_INF)
/* special expression check */
#define TJS_IEEE_D_IS_NaN(x) ((TJS_IEEE_D_EXP_MASK & (x)) == TJS_IEEE_D_EXP_MASK) && \
(((x) & TJS_IEEE_D_SIGNIFICAND_MSB_MASK) || \
(!((x) & TJS_IEEE_D_SIGNIFICAND_MSB_MASK) && \
((x) & (TJS_IEEE_D_SIGNIFICAND_MASK ^ TJS_IEEE_D_SIGNIFICAND_MSB_MASK))))
#define TJS_IEEE_D_IS_INF(x) (((TJS_IEEE_D_EXP_MASK & (x)) == TJS_IEEE_D_EXP_MASK) && \
(!((x) & TJS_IEEE_D_SIGNIFICAND_MASK)))
//---------------------------------------------------------------------------
// tTJSVariantString stuff
//---------------------------------------------------------------------------
#define TJS_VS_SHORT_LEN 21
//---------------------------------------------------------------------------
// tTJSVariantString
//---------------------------------------------------------------------------
#pragma pack(push, 4)
struct tTJSVariantString_S
{
tjs_int RefCount; // reference count - 1
tjs_char *LongString;
tjs_char ShortString[TJS_VS_SHORT_LEN +1];
tjs_int Length; // string length
tjs_uint32 HeapFlag;
tjs_uint32 Hint;
};
#pragma pack(pop)
//---------------------------------------------------------------------------
// tTJSRefHolder : a object holder for classes that has AddRef and Release methods
//---------------------------------------------------------------------------
template <typename T>
class tTJSRefHolder
{
private:
T *Object;
public:
tTJSRefHolder(T * ref) { Object = ref; Object->AddRef(); }
tTJSRefHolder(const tTJSRefHolder<T> &ref)
{
Object = ref.Object;
Object->AddRef();
}
~tTJSRefHolder() { Object->Release(); }
T* GetObject() { Object->AddRef(); return Object; }
T* GetObjectNoAddRef() { return Object; }
const tTJSRefHolder & operator = (const tTJSRefHolder & rhs)
{
if(rhs.Object != Object)
{
Object->Release();
Object = rhs.Object;
Object->AddRef();
}
return *this;
}
};
//---------------------------------------------------------------------------
// floating-point class checker
//---------------------------------------------------------------------------
// constants used in TJSGetFPClass
#define TJS_FC_CLASS_MASK 7
#define TJS_FC_SIGN_MASK 8
#define TJS_FC_CLASS_NORMAL 0
#define TJS_FC_CLASS_NAN 1
#define TJS_FC_CLASS_INF 2
#define TJS_FC_IS_NORMAL(x) (((x)&TJS_FC_CLASS_MASK) == TJS_FC_CLASS_NORMAL)
#define TJS_FC_IS_NAN(x) (((x)&TJS_FC_CLASS_MASK) == TJS_FC_CLASS_NAN)
#define TJS_FC_IS_INF(x) (((x)&TJS_FC_CLASS_MASK) == TJS_FC_CLASS_INF)
#define TJS_FC_IS_NEGATIVE(x) ((bool)((x) & TJS_FC_SIGN_MASK))
#define TJS_FC_IS_POSITIVE(x) (!TJS_FC_IS_NEGATIVE(x))
//---------------------------------------------------------------------------
// tTJSStringBufferLength
//---------------------------------------------------------------------------
#pragma pack(push, 4)
class tTJSStringBufferLength
{
public:
tjs_int n;
tTJSStringBufferLength(tjs_int n) {this->n = n;}
};
#pragma pack(pop)
//---------------------------------------------------------------------------
// tTJSString
//---------------------------------------------------------------------------
#pragma pack(push, 4)
class tTJSVariantString;
struct tTJSString_S
{
tTJSVariantString *Ptr;
};
#pragma pack(pop)
class tTJSString;
typedef tTJSString ttstr;
//---------------------------------------------------------------------------
// call flag type
//---------------------------------------------------------------------------
#define TJS_MEMBERENSURE 0x00000200 // create a member if not exists
#define TJS_MEMBERMUSTEXIST 0x00000400 // member *must* exist ( for Dictionary/Array )
#define TJS_IGNOREPROP 0x00000800 // ignore property invoking
#define TJS_HIDDENMEMBER 0x00001000 // member is hidden
#define TJS_STATICMEMBER 0x00010000 // member is not registered to the
// object (internal use)
#define TJS_ENUM_NO_VALUE 0x00100000 // values are not retrieved
// (for EnumMembers)
#define TJS_NIS_REGISTER 0x00000001 // set native pointer
#define TJS_NIS_GETINSTANCE 0x00000002 // get native pointer
#define TJS_CII_ADD 0x00000001 // register name
// 'num' argument passed to CII is to be igonored.
#define TJS_CII_GET 0x00000000 // retrieve name
#define TJS_CII_SET_FINALIZE 0x00000002 // register "finalize" method name
// (set empty string not to call the method)
// 'num' argument passed to CII is to be igonored.
#define TJS_CII_SET_MISSING 0x00000003 // register "missing" method name.
// the method is called when the member is not present.
// (set empty string not to call the method)
// 'num' argument passed to CII is to be igonored.
// the method is to be called with three arguments;
// get_or_set : false for get, true for set
// name : member name
// value : value property; you must
// : dereference using unary '*' operator.
// the method must return true for found, false for not-found.
#define TJS_OL_LOCK 0x00000001 // Lock the object
#define TJS_OL_UNLOCK 0x00000002 // Unlock the object
//---------------------------------------------------------------------------
// Operation flag
//---------------------------------------------------------------------------
#define TJS_OP_BAND 0x0001
#define TJS_OP_BOR 0x0002
#define TJS_OP_BXOR 0x0003
#define TJS_OP_SUB 0x0004
#define TJS_OP_ADD 0x0005
#define TJS_OP_MOD 0x0006
#define TJS_OP_DIV 0x0007
#define TJS_OP_IDIV 0x0008
#define TJS_OP_MUL 0x0009
#define TJS_OP_LOR 0x000a
#define TJS_OP_LAND 0x000b
#define TJS_OP_SAR 0x000c
#define TJS_OP_SAL 0x000d
#define TJS_OP_SR 0x000e
#define TJS_OP_INC 0x000f
#define TJS_OP_DEC 0x0010
#define TJS_OP_MASK 0x001f
#define TJS_OP_MIN TJS_OP_BAND
#define TJS_OP_MAX TJS_OP_DEC
/* SAR = Shift Arithmetic Right, SR = Shift (bitwise) Right */
//---------------------------------------------------------------------------
// iTJSDispatch
//---------------------------------------------------------------------------
/*
iTJSDispatch interface
*/
class tTJSVariant;
class tTJSVariantClosure;
class tTJSVariantString;
class iTJSNativeInstance;
class iTJSDispatch2
{
/*
methods, that have "ByNum" at the end of the name, have
"num" parameter that enables the function to call a member with number directly.
following two have the same effect:
FuncCall(nullptr, L"123", nullptr, 0, nullptr, nullptr);
FuncCallByNum(nullptr, 123, nullptr, 0, nullptr, nullptr);
*/
public:
virtual tjs_uint TJS_INTF_METHOD AddRef(void) = 0;
virtual tjs_uint TJS_INTF_METHOD Release(void) = 0;
public:
virtual tjs_error TJS_INTF_METHOD
FuncCall( // function invocation
tjs_uint32 flag, // calling flag
const tjs_char * membername,// member name ( nullptr 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"
) = 0;
virtual tjs_error TJS_INTF_METHOD
FuncCallByNum( // function invocation by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
tTJSVariant *result, // result
tjs_int numparams, // number of parameters
tTJSVariant **param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
PropGet( // property get
tjs_uint32 flag, // calling flag
const tjs_char * membername,// member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
tTJSVariant *result, // result
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
PropGetByNum( // property get by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
tTJSVariant *result, // result
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
PropSet( // property set
tjs_uint32 flag, // calling flag
const tjs_char *membername, // member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
const tTJSVariant *param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
PropSetByNum( // property set by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
const tTJSVariant *param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
GetCount( // get member count
tjs_int *result, // variable that receives the result
const tjs_char *membername, // member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
GetCountByNum( // get member count by index number
tjs_int *result, // variable that receives the result
tjs_int num, // by index number
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
PropSetByVS( // property set by tTJSVariantString, for internal use
tjs_uint32 flag, // calling flag
tTJSVariantString *membername, // member name ( nullptr for a default member )
const tTJSVariant *param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
EnumMembers( // enumerate members
tjs_uint32 flag, // enumeration flag
tTJSVariantClosure *callback, // callback function interface ( called on each member )
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
DeleteMember( // delete member
tjs_uint32 flag, // calling flag
const tjs_char *membername, // member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
DeleteMemberByNum( // delete member by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
Invalidate( // invalidation
tjs_uint32 flag, // calling flag
const tjs_char *membername, // member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
InvalidateByNum( // invalidation by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
IsValid( // get validation, returns TJS_S_TRUE (valid) or TJS_S_FALSE (invalid)
tjs_uint32 flag, // calling flag
const tjs_char *membername, // member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
IsValidByNum( // get validation by index number, returns TJS_S_TRUE (valid) or TJS_S_FALSE (invalid)
tjs_uint32 flag, // calling flag
tjs_int num, // index number
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
CreateNew( // create new object
tjs_uint32 flag, // calling flag
const tjs_char * membername,// member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
iTJSDispatch2 **result, // result
tjs_int numparams, // number of parameters
tTJSVariant **param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
CreateNewByNum( // create new object by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
iTJSDispatch2 **result, // result
tjs_int numparams, // number of parameters
tTJSVariant **param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
Reserved1(
) = 0;
virtual tjs_error TJS_INTF_METHOD
IsInstanceOf( // class instance matching returns TJS_S_FALSE or TJS_S_TRUE
tjs_uint32 flag, // calling flag
const tjs_char *membername, // member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
const tjs_char *classname, // class name to inquire
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
IsInstanceOfByNum( // class instance matching by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
const tjs_char *classname, // class name to inquire
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
Operation( // operation with member
tjs_uint32 flag, // calling flag
const tjs_char *membername, // member name ( nullptr for a default member )
tjs_uint32 *hint, // hint for the member name (in/out)
tTJSVariant *result, // result ( can be nullptr )
const tTJSVariant *param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
OperationByNum( // operation with member by index number
tjs_uint32 flag, // calling flag
tjs_int num, // index number
tTJSVariant *result, // result ( can be nullptr )
const tTJSVariant *param, // parameters
iTJSDispatch2 *objthis // object as "this"
) = 0;
virtual tjs_error TJS_INTF_METHOD
NativeInstanceSupport( // support for native instance
tjs_uint32 flag, // calling flag
tjs_int32 classid, // native class ID
iTJSNativeInstance **pointer// object pointer
) = 0;
virtual tjs_error TJS_INTF_METHOD
ClassInstanceInfo( // support for class instance information
tjs_uint32 flag, // calling flag
tjs_uint num, // index number
tTJSVariant *value // the name
) = 0;
virtual tjs_error TJS_INTF_METHOD
Reserved2(
) = 0;
virtual tjs_error TJS_INTF_METHOD
Reserved3(
) = 0;
};
//---------------------------------------------------------------------------
class iTJSNativeInstance
{
public:
virtual tjs_error TJS_INTF_METHOD Construct(tjs_int numparams,
tTJSVariant **param, iTJSDispatch2 *tjs_obj) = 0;
// TJS constructor
virtual void TJS_INTF_METHOD Invalidate() = 0;
// called before destruction
virtual void TJS_INTF_METHOD Destruct() = 0;
// must destruct itself
};
//---------------------------------------------------------------------------
// return values as tjs_error
//---------------------------------------------------------------------------
#define TJS_E_MEMBERNOTFOUND (-1001)
#define TJS_E_NOTIMPL (-1002)
#define TJS_E_INVALIDPARAM (-1003)
#define TJS_E_BADPARAMCOUNT (-1004)
#define TJS_E_INVALIDTYPE (-1005)
#define TJS_E_INVALIDOBJECT (-1006)
#define TJS_E_ACCESSDENYED (-1007)
#define TJS_E_NATIVECLASSCRASH (-1008)
#define TJS_S_TRUE (1)
#define TJS_S_FALSE (2)
#define TJS_S_OK (0)
#define TJS_E_FAIL (-1)
#define TJS_S_MAX (2)
// maximum possible number of success status.
// numbers over this may be regarded as a failure in
// strict-checking mode.
#ifdef TJS_STRICT_ERROR_CODE_CHECK
static inline bool TJS_FAILED(tjs_error hr)
{
if(hr < 0) return true;
if(hr > TJS_S_MAX) return true;
return false;
}
#else
#define TJS_FAILED(x) ((x)<0)
#endif
#define TJS_SUCCEEDED(x) (!TJS_FAILED(x))
static inline bool TJSIsObjectValid(tjs_error hr)
{
// checks object validity by returning value of iTJSDispatch2::IsValid
if(hr == TJS_S_TRUE) return true; // mostly expected value for valid object
if(hr == TJS_E_NOTIMPL) return true; // also valid for object which does not implement IsValid
return false; // otherwise the object is not valid
}
//---------------------------------------------------------------------------
// tTJSNativeInstanceType
//---------------------------------------------------------------------------
enum tTJSNativeInstanceType
{
nitClass,
nitMethod,
nitProperty
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// tTJSNativeInstance
//---------------------------------------------------------------------------
class tTJSNativeInstance : public iTJSNativeInstance
{
public:
virtual tjs_error TJS_INTF_METHOD Construct(tjs_int numparams,
tTJSVariant **param, iTJSDispatch2 *tjs_obj) {return TJS_S_OK;}
virtual void TJS_INTF_METHOD Invalidate() {;}
virtual void TJS_INTF_METHOD Destruct() { delete this; }
virtual ~tTJSNativeInstance() {;};
};
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// tTJSNativeClassMethod
//---------------------------------------------------------------------------
typedef tjs_error (TJS_INTF_METHOD *tTJSNativeClassMethodCallback)
(tTJSVariant *result,tjs_int numparams, tTJSVariant **param,
iTJSDispatch2 *objthis);
class tTJSNativeClassMethod : public iTJSDispatch2 { };
//---------------------------------------------------------------------------
// tTJSNativeClassProperty
//---------------------------------------------------------------------------
typedef tjs_error (TJS_INTF_METHOD *tTJSNativeClassPropertyGetCallback)
(tTJSVariant *result, iTJSDispatch2 *objthis);
typedef tjs_error (TJS_INTF_METHOD *tTJSNativeClassPropertySetCallback)
(const tTJSVariant *param, iTJSDispatch2 *objthis);
class tTJSNativeClassProperty : public iTJSDispatch2 { };
//---------------------------------------------------------------------------
// tTJSNativeClassForPlugin : service class for plugins
//---------------------------------------------------------------------------
typedef iTJSNativeInstance * (TJS_INTF_METHOD *tTJSCreateNativeInstance)();
class tTJSNativeClass : public iTJSDispatch2 { };
class tTJSNativeClassForPlugin : public tTJSNativeClass { };
//---------------------------------------------------------------------------
// following macros are to be written in the constructor of child class
// to define native methods/properties.
#define TJS_NCM_REG_THIS classobj
#define TJS_NATIVE_SET_ClassID TJS_NATIVE_CLASSID_NAME = TJS_NCM_CLASSID;
#define TJS_GET_NATIVE_INSTANCE(varname, typename) \
if(!objthis) return TJS_E_NATIVECLASSCRASH; \
typename *varname; \
{ \
tjs_error hr; \
hr = objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE, \
TJS_NATIVE_CLASSID_NAME, (iTJSNativeInstance**)&varname); \
if(TJS_FAILED(hr)) return TJS_E_NATIVECLASSCRASH; \
}
#define TJS_GET_NATIVE_INSTANCE_OUTER(classname, varname, typename) \
if(!objthis) return TJS_E_NATIVECLASSCRASH; \
typename *varname; \
{ \
tjs_error hr; \
hr = objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE, \
classname::ClassID, (iTJSNativeInstance**)&varname); \
if(TJS_FAILED(hr)) return TJS_E_NATIVECLASSCRASH; \
}
#define TJS_BEGIN_NATIVE_MEMBERS(classname) \
{ \
static const tjs_char *__classname = TJS_W(#classname); \
static tjs_int32 TJS_NCM_CLASSID = \
TJSRegisterNativeClass(__classname); \
TJSNativeClassSetClassID(TJS_NCM_REG_THIS, TJS_NCM_CLASSID); \
TJS_NATIVE_SET_ClassID
#define TJS_BEGIN_NATIVE_METHOD_DECL(name) \
struct NCM_##name { \
static tjs_error TJS_INTF_METHOD \
Process( tTJSVariant *result, \
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) {
#define TJS_END_NATIVE_METHOD_DECL_INT \
} \
};
#define TJS_END_NATIVE_METHOD_DECL(name) \
TJS_END_NATIVE_METHOD_DECL_INT \
TJSNativeClassRegisterNCM(TJS_NCM_REG_THIS, TJS_W(#name), \
TJSCreateNativeClassMethod(NCM_##name::Process), __classname, nitMethod);
#define TJS_END_NATIVE_HIDDEN_METHOD_DECL(name) \
TJS_END_NATIVE_METHOD_DECL_INT \
TJSNativeClassRegisterNCM(TJS_NCM_REG_THIS, TJS_W(#name), \
TJSCreateNativeClassMethod(NCM_##name::Process), __classname, nitMethod, \
TJS_HIDDENMEMBER);
#define TJS_END_NATIVE_STATIC_METHOD_DECL(name) \
TJS_END_NATIVE_METHOD_DECL_INT \
TJSNativeClassRegisterNCM(TJS_NCM_REG_THIS, TJS_W(#name), \
TJSCreateNativeClassMethod(NCM_##name::Process), __classname, nitMethod, \
TJS_STATICMEMBER);
#define TJS_END_NATIVE_METHOD_DECL_OUTER(object, name) \
TJS_END_NATIVE_METHOD_DECL_INT \
TJSNativeClassRegisterNCM((object), TJS_W(#name), \
TJSCreateNativeClassMethod(NCM_##name::Process), \
(object)->GetClassName().c_str(), nitMethod);
#define TJS_END_NATIVE_STATIC_METHOD_DECL_OUTER(object, name) \
TJS_END_NATIVE_METHOD_DECL_INT \
TJSNativeClassRegisterNCM((object), TJS_W(#name), \
TJSCreateNativeClassMethod(NCM_##name::Process), \
(object)->GetClassName().c_str(), nitMethod, TJS_STATICMEMBER);
#define TJS_DECL_EMPTY_FINALIZE_METHOD \
TJS_BEGIN_NATIVE_METHOD_DECL(finalize) \
{ return TJS_S_OK; } \
TJS_END_NATIVE_METHOD_DECL(finalize)
#define TJS_NATIVE_CONSTRUCTOR_CALL_NATIVE_CONSTRUCTOR(varname, typename) \
typename *varname; \
{ \
tjs_error hr; \
hr = objthis->NativeInstanceSupport(TJS_NIS_GETINSTANCE, \
TJS_NATIVE_CLASSID_NAME, \
(iTJSNativeInstance**)&varname); \
if(TJS_FAILED(hr)) return TJS_E_NATIVECLASSCRASH; \
if(!varname) return TJS_E_NATIVECLASSCRASH; \
hr = varname->Construct(numparams, param, objthis); \
if(TJS_FAILED(hr)) return hr; \
}
#define TJS_BEGIN_NATIVE_CONSTRUCTOR_DECL_NO_INSTANCE(classname) \
struct NCM_##classname { \
static tjs_error TJS_INTF_METHOD \
Process(tTJSVariant *result, \
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) {
#define TJS_BEGIN_NATIVE_CONSTRUCTOR_DECL(varname, typename, classname) \
TJS_BEGIN_NATIVE_CONSTRUCTOR_DECL_NO_INSTANCE(classname) \
TJS_NATIVE_CONSTRUCTOR_CALL_NATIVE_CONSTRUCTOR(varname, typename)
#define TJS_END_NATIVE_CONSTRUCTOR_DECL(name) \
TJS_END_NATIVE_METHOD_DECL_INT \
TJSNativeClassRegisterNCM(TJS_NCM_REG_THIS, TJS_W(#name), \
TJSCreateNativeClassConstructor(NCM_##name::Process), __classname, \
nitMethod);
#define TJS_END_NATIVE_STATIC_CONSTRUCTOR_DECL(name) \
TJS_END_NATIVE_METHOD_DECL_INT \
TJSNativeClassRegisterNCM(TJS_NCM_REG_THIS, TJS_W(#name), \
TJSCreateNativeClassConstructor(NCM_##name::Process), __classname, \
nitMethod, TJS_STATICMEMBER);
#define TJS_BEGIN_NATIVE_PROP_DECL(name) \
struct NCM_##name
#define TJS_END_NATIVE_PROP_DECL(name) \
;TJSNativeClassRegisterNCM(TJS_NCM_REG_THIS, TJS_W(#name), \
TJSCreateNativeClassProperty(NCM_##name::Get, NCM_##name::Set), \
__classname, nitProperty);
#define TJS_END_NATIVE_PROP_DECL_OUTER(object, name) \
;TJSNativeClassRegisterNCM((object), TJS_W(#name), \
TJSCreateNativeClassProperty(NCM_##name::Get, NCM_##name::Set), \
(object)->GetClassName().c_str(), nitProperty);
#define TJS_END_NATIVE_STATIC_PROP_DECL(name) \
;TJSNativeClassRegisterNCM(TJS_NCM_REG_THIS, TJS_W(#name), \
TJSCreateNativeClassProperty(NCM_##name::Get, NCM_##name::Set), \
__classname, nitProperty, TJS_STATICMEMBER);
#define TJS_END_NATIVE_STATIC_PROP_DECL_OUTER(object, name) \
;TJSNativeClassRegisterNCM((object), TJS_W(#name), \
TJSCreateNativeClassProperty(NCM_##name::Get, NCM_##name::Set), \
(object)->GetClassName().c_str(), nitProperty, TJS_STATICMEMBER);
#define TJS_BEGIN_NATIVE_PROP_GETTER \
static tjs_error TJS_INTF_METHOD Get(tTJSVariant *result, \
iTJSDispatch2 *objthis) { \
#define TJS_END_NATIVE_PROP_GETTER \
}
#define TJS_DENY_NATIVE_PROP_GETTER \
static tjs_error TJS_INTF_METHOD Get(tTJSVariant *result, \
iTJSDispatch2 *objthis) \
{ return TJS_E_ACCESSDENYED; }
#define TJS_BEGIN_NATIVE_PROP_SETTER \
static tjs_error TJS_INTF_METHOD Set(const tTJSVariant *param, \
iTJSDispatch2 *objthis) { \
#define TJS_END_NATIVE_PROP_SETTER \
}
#define TJS_DENY_NATIVE_PROP_SETTER \
static tjs_error TJS_INTF_METHOD Set(const tTJSVariant *param, \
iTJSDispatch2 *objthis) \
{ return TJS_E_ACCESSDENYED; }
#define TJS_END_NATIVE_MEMBERS \
}
#define TJS_PARAM_EXIST(num) (numparams>(num) ? param[num]->Type()!=tvtVoid : false)
//---------------------------------------------------------------------------
// tTJSVariantOctet
//---------------------------------------------------------------------------
#pragma pack(push, 4)
struct tTJSVariantOctet_S
{
tjs_uint Length;
tjs_int RefCount;
tjs_uint8 *Data;
};
#pragma pack(pop)
//---------------------------------------------------------------------------
// tTJSVariant_S
//---------------------------------------------------------------------------
#ifdef __BORLANDC__
#pragma option push -b
#endif
enum tTJSVariantType
{
tvtVoid, // empty
tvtObject,
tvtString,
tvtOctet, // octet binary data
tvtInteger,
tvtReal
};
#ifdef __BORLANDC__
#pragma option pop
#endif
#pragma pack(push, 4)
class iTJSDispatch2;
struct tTJSVariantClosure_S
{
iTJSDispatch2 *Object;
iTJSDispatch2 *ObjThis;
};
class tTJSVariantClosure;
class tTJSVariantString;
class tTJSVariantOctet;
struct tTJSVariant_S
{
//---- data members -----------------------------------------------------
#define tTJSVariant_BITCOPY(a,b) \
{\
*(tTJSVariant_S*)&(a) = *(tTJSVariant_S*)&(b); \
}
union
{
tTJSVariantClosure_S Object;
tTVInteger Integer;
tTVReal Real;
tTJSVariantString *String;
tTJSVariantOctet *Octet;
};
tTJSVariantType vt;
};
#pragma pack(pop)
//---------------------------------------------------------------------------
// tTJSVariantClosure
//---------------------------------------------------------------------------
void TJSThrowNullAccess();
class tTJSVariantClosure : public tTJSVariantClosure_S
{
// tTJSVariantClosure does not provide any function of object lifetime
// namagement. ( AddRef and Release are provided but tTJSVariantClosure
// has no responsibility for them )
public:
tTJSVariantClosure() {;} // note that default constructor does nothing
tTJSVariantClosure(iTJSDispatch2 *obj, iTJSDispatch2 *objthis = nullptr)
{ Object = obj, ObjThis = objthis; }
iTJSDispatch2 * SelectObjectNoAddRef()
{ return ObjThis ? ObjThis : Object; }
public:
bool operator == (const tTJSVariantClosure &rhs)
{
return Object == rhs.Object && ObjThis == rhs.ObjThis;
}
bool operator != (const tTJSVariantClosure &rhs)
{
return ! this->operator ==(rhs);
}
void AddRef()
{
if(Object) Object->AddRef();
if(ObjThis) ObjThis->AddRef();
}
void Release()
{
if(Object) Object->Release();
if(ObjThis) ObjThis->Release();
}
tjs_error
FuncCall(tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
tTJSVariant *result,
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) const
{
if(!Object) TJSThrowNullAccess();
return Object->FuncCall(flag, membername, hint, result, numparams, param,
ObjThis?ObjThis:(objthis?objthis:Object));
}
tjs_error
FuncCallByNum(tjs_uint32 flag, tjs_int num, tTJSVariant *result,
tjs_int numparams, tTJSVariant **param, iTJSDispatch2 *objthis) const
{
if(!Object) TJSThrowNullAccess();
return Object->FuncCallByNum(flag, num, result, numparams, param,
ObjThis?ObjThis:(objthis?objthis:Object));
}
tjs_error
PropGet(tjs_uint32 flag, const tjs_char * membername, tjs_uint32 *hint,
tTJSVariant *result,
iTJSDispatch2 *objthis) const
{
if(!Object) TJSThrowNullAccess();
return Object->PropGet(flag, membername, hint, result,
ObjThis?ObjThis:(objthis?objthis:Object));