forked from olebedev/go-duktape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.go
1609 lines (1367 loc) · 52 KB
/
api.go
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
package duktape
/*
#cgo CFLAGS: -std=c99 -Os -fomit-frame-pointer -fstrict-aliasing
#include "duktape.h"
#include "duk_logging.h"
#include "duk_v1_compat.h"
#include "duk_print_alert.h"
static void _duk_eval_string(duk_context *ctx, const char *str) {
duk_eval_string(ctx, str);
}
static void _duk_compile(duk_context *ctx, duk_uint_t flags) {
duk_compile(ctx, flags);
}
static void _duk_compile_file(duk_context *ctx, duk_uint_t flags, const char *path) {
duk_compile_file(ctx, flags, path);
}
static void _duk_compile_lstring(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) {
duk_compile_lstring(ctx, flags, src, len);
}
static void _duk_compile_lstring_filename(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) {
duk_compile_lstring_filename(ctx, flags, src, len);
}
static void _duk_compile_string(duk_context *ctx, duk_uint_t flags, const char *src) {
duk_compile_string(ctx, flags, src);
}
static void _duk_compile_string_filename(duk_context *ctx, duk_uint_t flags, const char *src) {
duk_compile_string_filename(ctx, flags, src);
}
static void _duk_dump_context_stderr(duk_context *ctx) {
duk_dump_context_stderr(ctx);
}
static void _duk_dump_context_stdout(duk_context *ctx) {
duk_dump_context_stdout(ctx);
}
static void _duk_eval(duk_context *ctx) {
duk_eval(ctx);
}
static void _duk_eval_file(duk_context *ctx, const char *path) {
duk_eval_file(ctx, path);
}
static void _duk_eval_file_noresult(duk_context *ctx, const char *path) {
duk_eval_file_noresult(ctx, path);
}
static void _duk_eval_lstring(duk_context *ctx, const char *src, duk_size_t len) {
duk_eval_lstring(ctx, src, len);
}
static void _duk_eval_lstring_noresult(duk_context *ctx, const char *src, duk_size_t len) {
duk_eval_lstring_noresult(ctx, src, len);
}
static void _duk_eval_noresult(duk_context *ctx) {
duk_eval_noresult(ctx);
}
static void _duk_eval_string_noresult(duk_context *ctx, const char *src) {
duk_eval_string_noresult(ctx, src);
}
static duk_bool_t _duk_is_error(duk_context *ctx, duk_idx_t index) {
return duk_is_error(ctx, index);
}
static duk_bool_t _duk_is_object_coercible(duk_context *ctx, duk_idx_t index) {
return duk_is_object_coercible(ctx, index);
}
static duk_int_t _duk_pcompile(duk_context *ctx, duk_uint_t flags) {
return duk_pcompile(ctx, flags);
}
static duk_int_t _duk_pcompile_file(duk_context *ctx, duk_uint_t flags, const char *path) {
return duk_pcompile_file(ctx, flags, path);
}
static duk_int_t _duk_pcompile_lstring(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) {
return duk_pcompile_lstring(ctx, flags, src, len);
}
static duk_int_t _duk_pcompile_lstring_filename(duk_context *ctx, duk_uint_t flags, const char *src, duk_size_t len) {
return duk_pcompile_lstring_filename(ctx, flags, src, len);
}
static duk_int_t _duk_pcompile_string(duk_context *ctx, duk_uint_t flags, const char *src) {
return duk_pcompile_string(ctx, flags, src);
}
static duk_int_t _duk_pcompile_string_filename(duk_context *ctx, duk_uint_t flags, const char *src) {
return duk_pcompile_string_filename(ctx, flags, src);
}
static duk_int_t _duk_peval(duk_context *ctx) {
return duk_peval(ctx);
}
static duk_int_t _duk_peval_file(duk_context *ctx, const char *path) {
return duk_peval_file(ctx, path);
}
static duk_int_t _duk_peval_file_noresult(duk_context *ctx, const char *path) {
return duk_peval_file_noresult(ctx, path);
}
static duk_int_t _duk_peval_lstring(duk_context *ctx, const char *src, duk_size_t len) {
return duk_peval_lstring(ctx, src, len);
}
static duk_int_t _duk_peval_lstring_noresult(duk_context *ctx, const char *src, duk_size_t len) {
return duk_peval_lstring_noresult(ctx, src, len);
}
static duk_int_t _duk_peval_noresult(duk_context *ctx) {
return duk_peval_noresult(ctx);
}
static duk_int_t _duk_peval_string(duk_context *ctx, const char *src) {
return duk_peval_string(ctx, src);
}
static duk_int_t _duk_peval_string_noresult(duk_context *ctx, const char *src) {
return duk_peval_string_noresult(ctx, src);
}
static const char *_duk_push_string_file(duk_context *ctx, const char *path) {
return duk_push_string_file(ctx, path);
}
static duk_idx_t _duk_push_thread(duk_context *ctx) {
return duk_push_thread(ctx);
}
static duk_idx_t _duk_push_thread_new_globalenv(duk_context *ctx) {
return duk_push_thread_new_globalenv(ctx);
}
static void _duk_require_object_coercible(duk_context *ctx, duk_idx_t index) {
duk_require_object_coercible(ctx, index);
}
static void _duk_require_type_mask(duk_context *ctx, duk_idx_t index, duk_uint_t mask) {
duk_require_type_mask(ctx, index, mask);
}
static const char *_duk_safe_to_string(duk_context *ctx, duk_idx_t index) {
return duk_safe_to_string(ctx, index);
}
static void _duk_xcopy_top(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count) {
duk_xcopy_top(to_ctx, from_ctx, count);
}
static void _duk_xmove_top(duk_context *to_ctx, duk_context *from_ctx, duk_idx_t count) {
duk_xmove_top(to_ctx, from_ctx, count);
}
static void *_duk_to_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
return duk_to_buffer(ctx, index, out_size);
}
static void *_duk_to_dynamic_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
return duk_to_dynamic_buffer(ctx, index, out_size);
}
static void *_duk_to_fixed_buffer(duk_context *ctx, duk_idx_t index, duk_size_t *out_size) {
return duk_to_fixed_buffer(ctx, index, out_size);
}
static duk_int_t _duk_is_primitive(duk_context *ctx, duk_idx_t index) {
return duk_is_primitive(ctx, index);
}
static void *_duk_push_buffer(duk_context *ctx, duk_size_t size, duk_bool_t dynamic) {
return duk_push_buffer(ctx, size, dynamic);
}
static void *_duk_push_fixed_buffer(duk_context *ctx, duk_size_t size) {
return duk_push_fixed_buffer(ctx, size);
}
static void *_duk_push_dynamic_buffer(duk_context *ctx, duk_size_t size) {
return duk_push_dynamic_buffer(ctx, size);
}
static void _duk_error(duk_context *ctx, duk_errcode_t err_code, const char *str) {
duk_error(ctx, err_code, "%s", str);
}
static void _duk_push_error_object(duk_context *ctx, duk_errcode_t err_code, const char *str) {
duk_push_error_object(ctx, err_code, "%s", str);
}
static void _duk_error_raw(duk_context *ctx, duk_errcode_t err_code, const char *filename, duk_int_t line, const char *text) {
duk_error_raw(ctx, err_code, filename, line, text);
}
static void _duk_log(duk_context *ctx, duk_int_t level, const char *str) {
duk_log(ctx, level, "%s", str);
}
static void _duk_push_external_buffer(duk_context *ctx) {
duk_push_external_buffer(ctx);
}
*/
import "C"
import (
"fmt"
"unsafe"
)
// See: http://duktape.org/api.html#duk_alloc
func (d *Context) Alloc(size int) {
C.duk_alloc(d.duk_context, C.duk_size_t(size))
}
// See: http://duktape.org/api.html#duk_alloc_raw
func (d *Context) AllocRaw(size int) {
C.duk_alloc_raw(d.duk_context, C.duk_size_t(size))
}
// See: http://duktape.org/api.html#duk_base64_decode
func (d *Context) Base64Decode(index int) {
C.duk_base64_decode(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_base64_encode
func (d *Context) Base64Encode(index int) string {
if s := C.duk_base64_encode(d.duk_context, C.duk_idx_t(index)); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_call
func (d *Context) Call(nargs int) {
C.duk_call(d.duk_context, C.duk_idx_t(nargs))
}
// See: http://duktape.org/api.html#duk_call_method
func (d *Context) CallMethod(nargs int) {
C.duk_call_method(d.duk_context, C.duk_idx_t(nargs))
}
// See: http://duktape.org/api.html#duk_call_prop
func (d *Context) CallProp(objIndex int, nargs int) {
C.duk_call_prop(d.duk_context, C.duk_idx_t(objIndex), C.duk_idx_t(nargs))
}
// See: http://duktape.org/api.html#duk_check_stack
func (d *Context) CheckStack(extra int) bool {
return int(C.duk_check_stack(d.duk_context, C.duk_idx_t(extra))) == 1
}
// See: http://duktape.org/api.html#duk_check_stack_top
func (d *Context) CheckStackTop(top int) bool {
return int(C.duk_check_stack_top(d.duk_context, C.duk_idx_t(top))) == 1
}
// See: http://duktape.org/api.html#duk_check_type
func (d *Context) CheckType(index int, typ int) bool {
return int(C.duk_check_type(d.duk_context, C.duk_idx_t(index), C.duk_int_t(typ))) == 1
}
// See: http://duktape.org/api.html#duk_check_type_mask
func (d *Context) CheckTypeMask(index int, mask uint) bool {
return int(C.duk_check_type_mask(d.duk_context, C.duk_idx_t(index), C.duk_uint_t(mask))) == 1
}
// See: http://duktape.org/api.html#duk_compact
func (d *Context) Compact(objIndex int) {
C.duk_compact(d.duk_context, C.duk_idx_t(objIndex))
}
// See: http://duktape.org/api.html#duk_compile
func (d *Context) Compile(flags uint) {
C._duk_compile(d.duk_context, C.duk_uint_t(flags))
}
// See: http://duktape.org/api.html#duk_compile_file
func (d *Context) CompileFile(flags uint, path string) {
__path__ := C.CString(path)
C._duk_compile_file(d.duk_context, C.duk_uint_t(flags), __path__)
C.free(unsafe.Pointer(__path__))
}
// See: http://duktape.org/api.html#duk_compile_lstring
func (d *Context) CompileLstring(flags uint, src string, len int) {
__src__ := C.CString(src)
C._duk_compile_lstring(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len))
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_compile_lstring_filename
func (d *Context) CompileLstringFilename(flags uint, src string, len int) {
__src__ := C.CString(src)
C._duk_compile_lstring_filename(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len))
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_compile_string
func (d *Context) CompileString(flags uint, src string) {
__src__ := C.CString(src)
C._duk_compile_string(d.duk_context, C.duk_uint_t(flags), __src__)
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_compile_string_filename
func (d *Context) CompileStringFilename(flags uint, src string) {
__src__ := C.CString(src)
C._duk_compile_string_filename(d.duk_context, C.duk_uint_t(flags), __src__)
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_concat
func (d *Context) Concat(count int) {
C.duk_concat(d.duk_context, C.duk_idx_t(count))
}
// See: http://duktape.org/api.html#duk_copy
func (d *Context) Copy(fromIndex int, toIndex int) {
C.duk_copy(d.duk_context, C.duk_idx_t(fromIndex), C.duk_idx_t(toIndex))
}
// See: http://duktape.org/api.html#duk_del_prop
func (d *Context) DelProp(objIndex int) bool {
return int(C.duk_del_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1
}
// See: http://duktape.org/api.html#duk_del_prop_index
func (d *Context) DelPropIndex(objIndex int, arrIndex uint) bool {
return int(C.duk_del_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1
}
// See: http://duktape.org/api.html#duk_del_prop_string
func (d *Context) DelPropString(objIndex int, key string) bool {
__key__ := C.CString(key)
result := int(C.duk_del_prop_string(d.duk_context, C.duk_idx_t(objIndex), __key__)) == 1
C.free(unsafe.Pointer(__key__))
return result
}
// See: http://duktape.org/api.html#duk_def_prop
func (d *Context) DefProp(objIndex int, flags uint) {
C.duk_def_prop(d.duk_context, C.duk_idx_t(objIndex), C.duk_uint_t(flags))
}
// See: http://duktape.org/api.html#duk_destroy_heap
func (d *Context) DestroyHeap() {
d.Gc(0)
C.duk_destroy_heap(d.duk_context)
d.duk_context = nil
}
// See: http://duktape.org/api.html#duk_dump_context_stderr
func (d *Context) DumpContextStderr() {
C._duk_dump_context_stderr(d.duk_context)
}
// See: http://duktape.org/api.html#duk_dump_context_stdout
func (d *Context) DumpContextStdout() {
C._duk_dump_context_stdout(d.duk_context)
}
// See: http://duktape.org/api.html#duk_dup
func (d *Context) Dup(fromIndex int) {
C.duk_dup(d.duk_context, C.duk_idx_t(fromIndex))
}
// See: http://duktape.org/api.html#duk_dup_top
func (d *Context) DupTop() {
C.duk_dup_top(d.duk_context)
}
// See: http://duktape.org/api.html#duk_enum
func (d *Context) Enum(objIndex int, enumFlags uint) {
C.duk_enum(d.duk_context, C.duk_idx_t(objIndex), C.duk_uint_t(enumFlags))
}
// See: http://duktape.org/api.html#duk_equals
func (d *Context) Equals(index1 int, index2 int) bool {
return int(C.duk_equals(d.duk_context, C.duk_idx_t(index1), C.duk_idx_t(index2))) == 1
}
// Error pushes a new Error object to the stack and throws it. This will call
// fmt.Sprint, forwarding arguments after the error code, to produce the
// Error's message.
//
// See: http://duktape.org/api.html#duk_error
func (d *Context) Error(errCode int, str string) {
__str__ := C.CString(str)
C._duk_error(d.duk_context, C.duk_errcode_t(errCode), __str__)
C.free(unsafe.Pointer(__str__))
}
func (d *Context) ErrorRaw(errCode int, filename string, line int, errMsg string) {
__filename__ := C.CString(filename)
__errMsg__ := C.CString(errMsg)
C._duk_error_raw(d.duk_context, C.duk_errcode_t(errCode), __filename__, C.duk_int_t(line), __errMsg__)
C.free(unsafe.Pointer(__filename__))
C.free(unsafe.Pointer(__errMsg__))
}
// Errorf pushes a new Error object to the stack and throws it. This will call
// fmt.Sprintf, forwarding the format string and additional arguments, to
// produce the Error's message.
//
// See: http://duktape.org/api.html#duk_error
func (d *Context) Errorf(errCode int, format string, a ...interface{}) {
str := fmt.Sprintf(format, a...)
__str__ := C.CString(str)
C._duk_error(d.duk_context, C.duk_errcode_t(errCode), __str__)
C.free(unsafe.Pointer(__str__))
}
// See: http://duktape.org/api.html#duk_eval
func (d *Context) Eval() {
C._duk_eval(d.duk_context)
}
// See: http://duktape.org/api.html#duk_eval_file
func (d *Context) EvalFile(path string) {
__path__ := C.CString(path)
C._duk_eval_file(d.duk_context, __path__)
C.free(unsafe.Pointer(__path__))
}
// See: http://duktape.org/api.html#duk_eval_file_noresult
func (d *Context) EvalFileNoresult(path string) {
__path__ := C.CString(path)
C._duk_eval_file_noresult(d.duk_context, __path__)
C.free(unsafe.Pointer(__path__))
}
// See: http://duktape.org/api.html#duk_eval_lstring
func (d *Context) EvalLstring(src string, len int) {
__src__ := C.CString(src)
C._duk_eval_lstring(d.duk_context, __src__, C.duk_size_t(len))
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_eval_lstring_noresult
func (d *Context) EvalLstringNoresult(src string, len int) {
__src__ := C.CString(src)
C._duk_eval_lstring_noresult(d.duk_context, __src__, C.duk_size_t(len))
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_eval_noresult
func (d *Context) EvalNoresult() {
C._duk_eval_noresult(d.duk_context)
}
// See: http://duktape.org/api.html#duk_eval_string
func (d *Context) EvalString(src string) {
__src__ := C.CString(src)
C._duk_eval_string(d.duk_context, __src__)
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_eval_string_noresult
func (d *Context) EvalStringNoresult(src string) {
__src__ := C.CString(src)
C._duk_eval_string_noresult(d.duk_context, __src__)
C.free(unsafe.Pointer(__src__))
}
// See: http://duktape.org/api.html#duk_fatal
func (d *Context) Fatal(errCode int, errMsg string) {
__errMsg__ := C.CString(errMsg)
defer C.free(unsafe.Pointer(__errMsg__))
C.duk_fatal_raw(d.duk_context, __errMsg__)
}
// See: http://duktape.org/api.html#duk_gc
func (d *Context) Gc(flags uint) {
C.duk_gc(d.duk_context, C.duk_uint_t(flags))
}
// See: http://duktape.org/api.html#duk_get_boolean
func (d *Context) GetBoolean(index int) bool {
return int(C.duk_get_boolean(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_get_buffer
func (d *Context) GetBuffer(index int, outSize int) {
C.duk_get_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
}
// See: http://duktape.org/api.html#duk_get_context
func (d *Context) GetContext(index int) *Context {
return contextFromPointer(C.duk_get_context(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_current_magic
func (d *Context) GetCurrentMagic() int {
return int(C.duk_get_current_magic(d.duk_context))
}
// See: http://duktape.org/api.html#duk_get_error_code
func (d *Context) GetErrorCode(index int) int {
code := int(C.duk_get_error_code(d.duk_context, C.duk_idx_t(index)))
return code
}
// See: http://duktape.org/api.html#duk_get_finalizer
func (d *Context) GetFinalizer(index int) {
C.duk_get_finalizer(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_get_global_string
func (d *Context) GetGlobalString(key string) bool {
__key__ := C.CString(key)
result := int(C.duk_get_global_string(d.duk_context, __key__)) == 1
C.free(unsafe.Pointer(__key__))
return result
}
// See: http://duktape.org/api.html#duk_get_heapptr
func (d *Context) GetHeapptr(index int) unsafe.Pointer {
return unsafe.Pointer(C.duk_get_heapptr(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_int
func (d *Context) GetInt(index int) int {
return int(C.duk_get_int(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_length
func (d *Context) GetLength(index int) int {
return int(C.duk_get_length(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_lstring
func (d *Context) GetLstring(index int, outLen int) string {
if s := C.duk_get_lstring(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outLen))); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_get_magic
func (d *Context) GetMagic(index int) int {
return int(C.duk_get_magic(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_number
func (d *Context) GetNumber(index int) float64 {
return float64(C.duk_get_number(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_pointer
func (d *Context) GetPointer(index int) unsafe.Pointer {
return C.duk_get_pointer(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_get_prop
func (d *Context) GetProp(objIndex int) bool {
return int(C.duk_get_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1
}
// See: http://duktape.org/api.html#duk_get_prop_index
func (d *Context) GetPropIndex(objIndex int, arrIndex uint) bool {
return int(C.duk_get_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1
}
// See: http://duktape.org/api.html#duk_get_prop_string
func (d *Context) GetPropString(objIndex int, key string) bool {
__key__ := C.CString(key)
result := int(C.duk_get_prop_string(d.duk_context, C.duk_idx_t(objIndex), __key__)) == 1
C.free(unsafe.Pointer(__key__))
return result
}
// See: http://duktape.org/api.html#duk_get_prototype
func (d *Context) GetPrototype(index int) {
C.duk_get_prototype(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_get_string
func (d *Context) GetString(i int) string {
if s := C.duk_get_string(d.duk_context, C.duk_idx_t(i)); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_get_top
func (d *Context) GetTop() int {
return int(C.duk_get_top(d.duk_context))
}
// See: http://duktape.org/api.html#duk_get_top_index
func (d *Context) GetTopIndex() int {
return int(C.duk_get_top_index(d.duk_context))
}
// See: http://duktape.org/api.html#duk_get_type
func (d *Context) GetType(index int) Type {
return Type(C.duk_get_type(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_type_mask
func (d *Context) GetTypeMask(index int) uint {
return uint(C.duk_get_type_mask(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_get_uint
func (d *Context) GetUint(index int) uint {
return uint(C.duk_get_uint(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_has_prop
func (d *Context) HasProp(objIndex int) bool {
return int(C.duk_has_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1
}
// See: http://duktape.org/api.html#duk_has_prop_index
func (d *Context) HasPropIndex(objIndex int, arrIndex uint) bool {
return int(C.duk_has_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1
}
// See: http://duktape.org/api.html#duk_has_prop_string
func (d *Context) HasPropString(objIndex int, key string) bool {
__key__ := C.CString(key)
result := int(C.duk_has_prop_string(d.duk_context, C.duk_idx_t(objIndex), __key__)) == 1
C.free(unsafe.Pointer(__key__))
return result
}
// See: http://duktape.org/api.html#duk_hex_decode
func (d *Context) HexDecode(index int) {
C.duk_hex_decode(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_hex_encode
func (d *Context) HexEncode(index int) string {
if s := C.duk_hex_encode(d.duk_context, C.duk_idx_t(index)); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_insert
func (d *Context) Insert(toIndex int) {
C.duk_insert(d.duk_context, C.duk_idx_t(toIndex))
}
// See: http://duktape.org/api.html#duk_is_array
func (d *Context) IsArray(index int) bool {
return int(C.duk_is_array(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_boolean
func (d *Context) IsBoolean(index int) bool {
return int(C.duk_is_boolean(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_bound_function
func (d *Context) IsBoundFunction(index int) bool {
return int(C.duk_is_bound_function(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_buffer
func (d *Context) IsBuffer(index int) bool {
return int(C.duk_is_buffer(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_c_function
func (d *Context) IsCFunction(index int) bool {
return int(C.duk_is_c_function(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_callable
func (d *Context) IsCallable(index int) bool {
return int(C.duk_is_function(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_constructor_call
func (d *Context) IsConstructorCall() bool {
return int(C.duk_is_constructor_call(d.duk_context)) == 1
}
// See: http://duktape.org/api.html#duk_is_dynamic_buffer
func (d *Context) IsDynamicBuffer(index int) bool {
return int(C.duk_is_dynamic_buffer(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_ecmascript_function
func (d *Context) IsEcmascriptFunction(index int) bool {
return int(C.duk_is_ecmascript_function(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_fixed_buffer
func (d *Context) IsFixedBuffer(index int) bool {
return int(C.duk_is_fixed_buffer(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_function
func (d *Context) IsFunction(index int) bool {
return int(C.duk_is_function(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_nan
func (d *Context) IsNan(index int) bool {
return int(C.duk_is_nan(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_null
func (d *Context) IsNull(index int) bool {
return int(C.duk_is_null(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_null_or_undefined
func (d *Context) IsNullOrUndefined(index int) bool {
return d.IsNull(index) || d.IsUndefined(index)
}
// See: http://duktape.org/api.html#duk_is_number
func (d *Context) IsNumber(index int) bool {
return int(C.duk_is_number(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_object
func (d *Context) IsObject(index int) bool {
return int(C.duk_is_object(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_error
func (d *Context) IsError(index int) bool {
return int(C._duk_is_error(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_object_coercible
func (d *Context) IsObjectCoercible(index int) bool {
return int(C._duk_is_object_coercible(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_pointer
func (d *Context) IsPointer(index int) bool {
return int(C.duk_is_pointer(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_primitive
func (d *Context) IsPrimitive(index int) bool {
return int(C._duk_is_primitive(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_strict_call
func (d *Context) IsStrictCall() bool {
return int(C.duk_is_strict_call(d.duk_context)) == 1
}
// See: http://duktape.org/api.html#duk_is_string
func (d *Context) IsString(index int) bool {
return int(C.duk_is_string(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_thread
func (d *Context) IsThread(index int) bool {
return int(C.duk_is_thread(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_undefined
func (d *Context) IsUndefined(index int) bool {
return int(C.duk_is_undefined(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_is_valid_index
func (d *Context) IsValidIndex(index int) bool {
return int(C.duk_is_valid_index(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_join
func (d *Context) Join(count int) {
C.duk_join(d.duk_context, C.duk_idx_t(count))
}
// See: http://duktape.org/api.html#duk_json_decode
func (d *Context) JsonDecode(index int) {
C.duk_json_decode(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_json_encode
func (d *Context) JsonEncode(index int) string {
if s := C.duk_json_encode(d.duk_context, C.duk_idx_t(index)); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_new
func (d *Context) New(nargs int) {
C.duk_new(d.duk_context, C.duk_idx_t(nargs))
}
// See: http://duktape.org/api.html#duk_next
func (d *Context) Next(enumIndex int, getValue bool) bool {
var __getValue__ int
if getValue {
__getValue__ = 1
}
return int(C.duk_next(d.duk_context, C.duk_idx_t(enumIndex), C.duk_bool_t(__getValue__))) == 1
}
// See: http://duktape.org/api.html#duk_normalize_index
func (d *Context) NormalizeIndex(index int) int {
return int(C.duk_normalize_index(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_pcall
func (d *Context) Pcall(nargs int) int {
return int(C.duk_pcall(d.duk_context, C.duk_idx_t(nargs)))
}
// See: http://duktape.org/api.html#duk_pcall_method
func (d *Context) PcallMethod(nargs int) int {
return int(C.duk_pcall_method(d.duk_context, C.duk_idx_t(nargs)))
}
// See: http://duktape.org/api.html#duk_pcall_prop
func (d *Context) PcallProp(objIndex int, nargs int) int {
return int(C.duk_pcall_prop(d.duk_context, C.duk_idx_t(objIndex), C.duk_idx_t(nargs)))
}
// See: http://duktape.org/api.html#duk_pcompile
func (d *Context) Pcompile(flags uint) error {
result := int(C._duk_pcompile(d.duk_context, C.duk_uint_t(flags)))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_pcompile_file
func (d *Context) PcompileFile(flags uint, path string) error {
__path__ := C.CString(path)
result := int(C._duk_pcompile_file(d.duk_context, C.duk_uint_t(flags), __path__))
C.free(unsafe.Pointer(__path__))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_pcompile_lstring
func (d *Context) PcompileLstring(flags uint, src string, len int) error {
__src__ := C.CString(src)
result := int(C._duk_pcompile_lstring(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len)))
C.free(unsafe.Pointer(__src__))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_pcompile_lstring_filename
func (d *Context) PcompileLstringFilename(flags uint, src string, len int) error {
__src__ := C.CString(src)
result := int(C._duk_pcompile_lstring_filename(d.duk_context, C.duk_uint_t(flags), __src__, C.duk_size_t(len)))
C.free(unsafe.Pointer(__src__))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_pcompile_string
func (d *Context) PcompileString(flags uint, src string) error {
__src__ := C.CString(src)
result := int(C._duk_pcompile_string(d.duk_context, C.duk_uint_t(flags), __src__))
C.free(unsafe.Pointer(__src__))
fmt.Println("result herhehreh", result)
return nil //d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_pcompile_string_filename
func (d *Context) PcompileStringFilename(flags uint, src string) error {
__src__ := C.CString(src)
result := int(C._duk_pcompile_string_filename(d.duk_context, C.duk_uint_t(flags), __src__))
C.free(unsafe.Pointer(__src__))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_peval
func (d *Context) Peval() error {
result := int(C._duk_peval(d.duk_context))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_peval_file
func (d *Context) PevalFile(path string) error {
__path__ := C.CString(path)
result := int(C._duk_peval_file(d.duk_context, __path__))
C.free(unsafe.Pointer(__path__))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_peval_file_noresult
func (d *Context) PevalFileNoresult(path string) int {
__path__ := C.CString(path)
result := int(C._duk_peval_file_noresult(d.duk_context, __path__))
C.free(unsafe.Pointer(__path__))
return result
}
// See: http://duktape.org/api.html#duk_peval_lstring
func (d *Context) PevalLstring(src string, len int) error {
__src__ := C.CString(src)
result := int(C._duk_peval_lstring(d.duk_context, __src__, C.duk_size_t(len)))
C.free(unsafe.Pointer(__src__))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_peval_lstring_noresult
func (d *Context) PevalLstringNoresult(src string, len int) int {
__src__ := C.CString(src)
result := int(C._duk_peval_lstring_noresult(d.duk_context, __src__, C.duk_size_t(len)))
C.free(unsafe.Pointer(__src__))
return result
}
// See: http://duktape.org/api.html#duk_peval_noresult
func (d *Context) PevalNoresult() int {
return int(C._duk_peval_noresult(d.duk_context))
}
// See: http://duktape.org/api.html#duk_peval_string
func (d *Context) PevalString(src string) error {
__src__ := C.CString(src)
result := int(C._duk_peval_string(d.duk_context, __src__))
C.free(unsafe.Pointer(__src__))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_peval_string_noresult
func (d *Context) PevalStringNoresult(src string) int {
__src__ := C.CString(src)
result := int(C._duk_peval_string_noresult(d.duk_context, __src__))
C.free(unsafe.Pointer(__src__))
return result
}
func (d *Context) castStringToError(result int) error {
if result == 0 {
return nil
}
err := &Error{}
for _, key := range []string{"name", "message", "fileName", "lineNumber", "stack"} {
d.GetPropString(-1, key)
switch key {
case "name":
err.Type = d.SafeToString(-1)
case "message":
err.Message = d.SafeToString(-1)
case "fileName":
err.FileName = d.SafeToString(-1)
case "lineNumber":
if d.IsNumber(-1) {
err.LineNumber = d.GetInt(-1)
}
case "stack":
err.Stack = d.SafeToString(-1)
}
d.Pop()
}
return err
}
// See: http://duktape.org/api.html#duk_pop
func (d *Context) Pop() {
if d.GetTop() == 0 {
return
}
C.duk_pop(d.duk_context)
}
// See: http://duktape.org/api.html#duk_pop_2
func (d *Context) Pop2() {
d.PopN(2)
}
// See: http://duktape.org/api.html#duk_pop_3
func (d *Context) Pop3() {
d.PopN(3)
}
// See: http://duktape.org/api.html#duk_pop_n
func (d *Context) PopN(count int) {
if d.GetTop() < count || count < 1 {
return
}
C.duk_pop_n(d.duk_context, C.duk_idx_t(count))
}
// See: http://duktape.org/api.html#duk_push_array
func (d *Context) PushArray() int {
return int(C.duk_push_array(d.duk_context))
}
// See: http://duktape.org/api.html#duk_push_boolean
func (d *Context) PushBoolean(val bool) {
var __val__ int
if val {
__val__ = 1
}
C.duk_push_boolean(d.duk_context, C.duk_bool_t(__val__))
}
// See: http://duktape.org/api.html#duk_push_buffer
func (d *Context) PushBuffer(size int, dynamic bool) {
var __dynamic__ int
if dynamic {
__dynamic__ = 1
}
C._duk_push_buffer(d.duk_context, C.duk_size_t(size), C.duk_bool_t(__dynamic__))
}
// See: http://duktape.org/api.html#duk_push_c_function
func (d *Context) PushCFunction(fn *[0]byte, nargs int) int {
return int(C.duk_push_c_function(d.duk_context, fn, C.duk_idx_t(nargs)))
}
// See: http://duktape.org/api.html#duk_push_context_dump
func (d *Context) PushContextDump() {
C.duk_push_context_dump(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_current_function
func (d *Context) PushCurrentFunction() {
C.duk_push_current_function(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_current_thread
func (d *Context) PushCurrentThread() {
C.duk_push_current_thread(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_dynamic_buffer
func (d *Context) PushDynamicBuffer(size int) {
C._duk_push_dynamic_buffer(d.duk_context, C.duk_size_t(size))
}
// See: http://duktape.org/api.html#duk_push_error_object
func (d *Context) PushErrorObject(errCode int, format string, value interface{}) {
__str__ := C.CString(fmt.Sprintf(format, value))
C._duk_push_error_object(d.duk_context, C.duk_errcode_t(errCode), __str__)