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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
|
package duktape
/*
#cgo !windows CFLAGS: -std=c99 -O3 -Wall -fomit-frame-pointer -fstrict-aliasing
#cgo windows CFLAGS: -O3 -Wall -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) unsafe.Pointer {
return 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) unsafe.Pointer {
return 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) (rawPtr unsafe.Pointer, outSize uint) {
rawPtr = C.duk_get_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
return rawPtr, 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) string {
if s := C.duk_get_lstring(d.duk_context, C.duk_idx_t(index), nil); 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) unsafe.Pointer {
var __dynamic__ int
if dynamic {
__dynamic__ = 1
}
return 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 int64) 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) unsafe.Pointer {
return 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__)
C.free(unsafe.Pointer(__str__))
}
// See: http://duktape.org/api.html#duk_push_false
func (d *Context) PushFalse() {
C.duk_push_false(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_fixed_buffer
func (d *Context) PushFixedBuffer(size int) unsafe.Pointer {
return C._duk_push_fixed_buffer(d.duk_context, C.duk_size_t(size))
}
// See: http://duktape.org/api.html#duk_push_global_object
func (d *Context) PushGlobalObject() {
C.duk_push_global_object(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_global_stash
func (d *Context) PushGlobalStash() {
C.duk_push_global_stash(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_heapptr
func (d *Context) PushHeapptr(ptr unsafe.Pointer) {
C.duk_push_heapptr(d.duk_context, ptr)
}
// See: http://duktape.org/api.html#duk_push_heap_stash
func (d *Context) PushHeapStash() {
C.duk_push_heap_stash(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_int
func (d *Context) PushInt(val int) {
C.duk_push_int(d.duk_context, C.duk_int_t(val))
}
// See: http://duktape.org/api.html#duk_push_lstring
func (d *Context) PushLstring(str string, len int) string {
__str__ := C.CString(str)
var result string
if s := C.duk_push_lstring(d.duk_context, __str__, C.duk_size_t(len)); s != nil {
result = C.GoString(s)
}
C.free(unsafe.Pointer(__str__))
return result
}
// See: http://duktape.org/api.html#duk_push_nan
func (d *Context) PushNan() {
C.duk_push_nan(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_null
func (d *Context) PushNull() {
C.duk_push_null(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_number
func (d *Context) PushNumber(val float64) {
C.duk_push_number(d.duk_context, C.duk_double_t(val))
}
// See: http://duktape.org/api.html#duk_push_object
func (d *Context) PushObject() int {
return int(C.duk_push_object(d.duk_context))
}
// See: http://duktape.org/api.html#duk_push_string
func (d *Context) PushString(str string) string {
__str__ := C.CString(str)
var result string
if s := C.duk_push_string(d.duk_context, __str__); s != nil {
result = C.GoString(s)
}
C.free(unsafe.Pointer(__str__))
return result
}
// See: http://duktape.org/api.html#duk_push_string_file
func (d *Context) PushStringFile(path string) string {
__path__ := C.CString(path)
var result string
if s := C._duk_push_string_file(d.duk_context, __path__); s != nil {
result = C.GoString(s)
}
C.free(unsafe.Pointer(__path__))
return result
}
// See: http://duktape.org/api.html#duk_push_this
func (d *Context) PushThis() {
C.duk_push_this(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_thread
func (d *Context) PushThread() int {
return int(C._duk_push_thread(d.duk_context))
}
// See: http://duktape.org/api.html#duk_push_thread_new_globalenv
func (d *Context) PushThreadNewGlobalenv() int {
return int(C._duk_push_thread_new_globalenv(d.duk_context))
}
// See: http://duktape.org/api.html#duk_push_thread_stash
func (d *Context) PushThreadStash(targetCtx *Context) {
C.duk_push_thread_stash(d.duk_context, targetCtx.duk_context)
}
// See: http://duktape.org/api.html#duk_push_true
func (d *Context) PushTrue() {
C.duk_push_true(d.duk_context)
}
// See: http://duktape.org/api.html#duk_push_uint
func (d *Context) PushUint(val uint) {
C.duk_push_uint(d.duk_context, C.duk_uint_t(val))
}
// See: http://duktape.org/api.html#duk_push_undefined
func (d *Context) PushUndefined() {
C.duk_push_undefined(d.duk_context)
}
// See: http://duktape.org/api.html#duk_put_global_string
func (d *Context) PutGlobalString(key string) bool {
__key__ := C.CString(key)
result := int(C.duk_put_global_string(d.duk_context, __key__)) == 1
C.free(unsafe.Pointer(__key__))
return result
}
// See: http://duktape.org/api.html#duk_put_prop
func (d *Context) PutProp(objIndex int) bool {
return int(C.duk_put_prop(d.duk_context, C.duk_idx_t(objIndex))) == 1
}
// See: http://duktape.org/api.html#duk_put_prop_index
func (d *Context) PutPropIndex(objIndex int, arrIndex uint) bool {
return int(C.duk_put_prop_index(d.duk_context, C.duk_idx_t(objIndex), C.duk_uarridx_t(arrIndex))) == 1
}
// See: http://duktape.org/api.html#duk_put_prop_string
func (d *Context) PutPropString(objIndex int, key string) bool {
__key__ := C.CString(key)
result := int(C.duk_put_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_remove
func (d *Context) Remove(index int) {
C.duk_remove(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_replace
func (d *Context) Replace(toIndex int) {
C.duk_replace(d.duk_context, C.duk_idx_t(toIndex))
}
// See: http://duktape.org/api.html#duk_require_boolean
func (d *Context) RequireBoolean(index int) bool {
return int(C.duk_require_boolean(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_require_buffer
func (d *Context) RequireBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) {
rawPtr = C.duk_require_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
return rawPtr, outSize
}
// See: http://duktape.org/api.html#duk_require_callable
func (d *Context) RequireCallable(index int) {
// At present, duk_require_callable is a macro that just calls duk_require_function.
// cgo does not support such macros we have to call it directly.
C.duk_require_function(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_require_context
func (d *Context) RequireContext(index int) *Context {
return contextFromPointer(C.duk_require_context(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_require_function
func (d *Context) RequireFunction(index int) {
C.duk_require_function(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_require_heapptr
func (d *Context) RequireHeapptr(index int) unsafe.Pointer {
return unsafe.Pointer(C.duk_require_heapptr(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_require_int
func (d *Context) RequireInt(index int) int {
return int(C.duk_require_int(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_require_lstring
func (d *Context) RequireLstring(index int) string {
if s := C.duk_require_lstring(d.duk_context, C.duk_idx_t(index), nil); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_require_normalize_index
func (d *Context) RequireNormalizeIndex(index int) int {
return int(C.duk_require_normalize_index(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_require_null
func (d *Context) RequireNull(index int) {
C.duk_require_null(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_require_number
func (d *Context) RequireNumber(index int) float64 {
return float64(C.duk_require_number(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_require_object_coercible
func (d *Context) RequireObjectCoercible(index int) {
C._duk_require_object_coercible(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_require_pointer
func (d *Context) RequirePointer(index int) unsafe.Pointer {
return C.duk_require_pointer(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_require_stack
func (d *Context) RequireStack(extra int) {
C.duk_require_stack(d.duk_context, C.duk_idx_t(extra))
}
// See: http://duktape.org/api.html#duk_require_stack_top
func (d *Context) RequireStackTop(top int) {
C.duk_require_stack_top(d.duk_context, C.duk_idx_t(top))
}
// See: http://duktape.org/api.html#duk_require_string
func (d *Context) RequireString(index int) string {
if s := C.duk_require_string(d.duk_context, C.duk_idx_t(index)); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_require_top_index
func (d *Context) RequireTopIndex() int {
return int(C.duk_require_top_index(d.duk_context))
}
// See: http://duktape.org/api.html#duk_require_type_mask
func (d *Context) RequireTypeMask(index int, mask uint) {
C._duk_require_type_mask(d.duk_context, C.duk_idx_t(index), C.duk_uint_t(mask))
}
// See: http://duktape.org/api.html#duk_require_uint
func (d *Context) RequireUint(index int) uint {
return uint(C.duk_require_uint(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_require_undefined
func (d *Context) RequireUndefined(index int) {
C.duk_require_undefined(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_require_valid_index
func (d *Context) RequireValidIndex(index int) {
C.duk_require_valid_index(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_resize_buffer
func (d *Context) ResizeBuffer(index int, newSize int) unsafe.Pointer {
return C.duk_resize_buffer(d.duk_context, C.duk_idx_t(index), C.duk_size_t(newSize))
}
// See: http://duktape.org/api.html#duk_safe_call
func (d *Context) SafeCall(fn, args *[0]byte, nargs, nrets int) int {
return int(C.duk_safe_call(
d.duk_context,
fn,
unsafe.Pointer(&args),
C.duk_idx_t(nargs),
C.duk_idx_t(nrets),
))
}
// See: http://duktape.org/api.html#duk_safe_to_lstring
func (d *Context) SafeToLstring(index int) string {
if s := C.duk_safe_to_lstring(d.duk_context, C.duk_idx_t(index), nil); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_safe_to_string
func (d *Context) SafeToString(index int) string {
if s := C._duk_safe_to_string(d.duk_context, C.duk_idx_t(index)); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_set_finalizer
func (d *Context) SetFinalizer(index int) {
C.duk_set_finalizer(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_set_global_object
func (d *Context) SetGlobalObject() {
C.duk_set_global_object(d.duk_context)
}
// See: http://duktape.org/api.html#duk_set_magic
func (d *Context) SetMagic(index int, magic int) {
C.duk_set_magic(d.duk_context, C.duk_idx_t(index), C.duk_int_t(magic))
}
// See: http://duktape.org/api.html#duk_set_prototype
func (d *Context) SetPrototype(index int) {
C.duk_set_prototype(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_set_top
func (d *Context) SetTop(index int) {
C.duk_set_top(d.duk_context, C.duk_idx_t(index))
}
func (d *Context) StrictEquals(index1 int, index2 int) bool {
return int(C.duk_strict_equals(d.duk_context, C.duk_idx_t(index1), C.duk_idx_t(index2))) == 1
}
// See: http://duktape.org/api.html#duk_substring
func (d *Context) Substring(index int, startCharOffset int, endCharOffset int) {
C.duk_substring(d.duk_context, C.duk_idx_t(index), C.duk_size_t(startCharOffset), C.duk_size_t(endCharOffset))
}
// See: http://duktape.org/api.html#duk_swap
func (d *Context) Swap(index1 int, index2 int) {
C.duk_swap(d.duk_context, C.duk_idx_t(index1), C.duk_idx_t(index2))
}
// See: http://duktape.org/api.html#duk_swap_top
func (d *Context) SwapTop(index int) {
C.duk_swap_top(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_throw
func (d *Context) Throw() {
C.duk_throw_raw(d.duk_context)
}
// See: http://duktape.org/api.html#duk_to_boolean
func (d *Context) ToBoolean(index int) bool {
return int(C.duk_to_boolean(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_to_buffer
func (d *Context) ToBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) {
rawPtr = C._duk_to_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
return rawPtr, outSize
}
// See: http://duktape.org/api.html#duk_to_defaultvalue
func (d *Context) ToDefaultvalue(index int, hint int) {
C.duk_to_defaultvalue(d.duk_context, C.duk_idx_t(index), C.duk_int_t(hint))
}
// See: http://duktape.org/api.html#duk_to_dynamic_buffer
func (d *Context) ToDynamicBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) {
rawPtr = C._duk_to_dynamic_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
return rawPtr, outSize
}
// See: http://duktape.org/api.html#duk_to_fixed_buffer
func (d *Context) ToFixedBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) {
rawPtr = C._duk_to_fixed_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
return rawPtr, outSize
}
// See: http://duktape.org/api.html#duk_to_int
func (d *Context) ToInt(index int) int {
return int(C.duk_to_int(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_to_int32
func (d *Context) ToInt32(index int) int32 {
return int32(C.duk_to_int32(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_to_lstring
func (d *Context) ToLstring(index int) string {
if s := C.duk_to_lstring(d.duk_context, C.duk_idx_t(index), nil); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_to_null
func (d *Context) ToNull(index int) {
C.duk_to_null(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_to_number
func (d *Context) ToNumber(index int) float64 {
return float64(C.duk_to_number(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_to_object
func (d *Context) ToObject(index int) {
C.duk_to_object(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_to_pointer
func (d *Context) ToPointer(index int) unsafe.Pointer {
return C.duk_to_pointer(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_to_primitive
func (d *Context) ToPrimitive(index int, hint int) {
C.duk_to_primitive(d.duk_context, C.duk_idx_t(index), C.duk_int_t(hint))
}
// See: http://duktape.org/api.html#duk_to_string
func (d *Context) ToString(index int) string {
if s := C.duk_to_string(d.duk_context, C.duk_idx_t(index)); s != nil {
return C.GoString(s)
}
return ""
}
// See: http://duktape.org/api.html#duk_to_uint
func (d *Context) ToUint(index int) uint {
return uint(C.duk_to_uint(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_to_uint16
func (d *Context) ToUint16(index int) uint16 {
return uint16(C.duk_to_uint16(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_to_uint32
func (d *Context) ToUint32(index int) uint32 {
return uint32(C.duk_to_uint32(d.duk_context, C.duk_idx_t(index)))
}
// See: http://duktape.org/api.html#duk_to_undefined
func (d *Context) ToUndefined(index int) {
C.duk_to_undefined(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_trim
func (d *Context) Trim(index int) {
C.duk_trim(d.duk_context, C.duk_idx_t(index))
}
// See: http://duktape.org/api.html#duk_xcopy_top
func (d *Context) XcopyTop(fromCtx *Context, count int) {
C._duk_xcopy_top(d.duk_context, fromCtx.duk_context, C.duk_idx_t(count))
}
// See: http://duktape.org/api.html#duk_xmove_top
func (d *Context) XmoveTop(fromCtx *Context, count int) {
C._duk_xmove_top(d.duk_context, fromCtx.duk_context, C.duk_idx_t(count))
}
// See: http://duktape.org/api.html#duk_push_pointer
func (d *Context) PushPointer(p unsafe.Pointer) {
C.duk_push_pointer(d.duk_context, p)
}
//---[ Duktape 1.3 API ]--- //
// See: http://duktape.org/api.html#duk_debugger_attach
func (d *Context) DebuggerAttach(
readFn,
writeFn,
peekFn,
readFlushFn,
writeFlushFn,
detachedFn *[0]byte,
uData unsafe.Pointer) {
C.duk_debugger_attach(
d.duk_context,
readFn,
writeFn,
peekFn,
readFlushFn,
writeFlushFn,
nil,
detachedFn,
uData,
)
}
// See: http://duktape.org/api.html#duk_debugger_cooperate
func (d *Context) DebuggerCooperate() {
C.duk_debugger_cooperate(d.duk_context)
}
// See: http://duktape.org/api.html#duk_debugger_detach
func (d *Context) DebuggerDetach() {
C.duk_debugger_detach(d.duk_context)
}
// See: http://duktape.org/api.html#duk_dump_function
func (d *Context) DumpFunction() {
C.duk_dump_function(d.duk_context)
}
// See: http://duktape.org/api.html#duk_error_va
func (d *Context) ErrorVa(errCode int, a ...interface{}) {
str := fmt.Sprint(a...)
d.Error(errCode, str)
}
// See: http://duktape.org/api.html#duk_instanceof
func (d *Context) Instanceof(idx1, idx2 int) bool {
return int(C.duk_instanceof(d.duk_context, C.duk_idx_t(idx1), C.duk_idx_t(idx2))) == 1
}
// See: http://duktape.org/api.html#duk_is_lightfunc
func (d *Context) IsLightfunc(index int) bool {
return int(C.duk_is_lightfunc(d.duk_context, C.duk_idx_t(index))) == 1
}
// See: http://duktape.org/api.html#duk_load_function
func (d *Context) LoadFunction() {
C.duk_load_function(d.duk_context)
}
// See: http://duktape.org/api.html#duk_log
func (d *Context) Log(loglevel int, format string, value interface{}) {
__str__ := C.CString(fmt.Sprintf(format, value))
C._duk_log(d.duk_context, C.duk_int_t(loglevel), __str__)
C.free(unsafe.Pointer(__str__))
}
// See: http://duktape.org/api.html#duk_log_va
func (d *Context) LogVa(logLevel int, format string, values ...interface{}) {
__str__ := C.CString(fmt.Sprintf(format, values...))
C._duk_log(d.duk_context, C.duk_int_t(logLevel), __str__)
C.free(unsafe.Pointer(__str__))
}
// See: http://duktape.org/api.html#duk_pnew
func (d *Context) Pnew(nargs int) error {
result := int(C.duk_pnew(d.duk_context, C.duk_idx_t(nargs)))
return d.castStringToError(result)
}
// See: http://duktape.org/api.html#duk_push_buffer_object
func (d *Context) PushBufferObject(bufferIdx, size, length int, flags uint) {
C.duk_push_buffer_object(
d.duk_context,
C.duk_idx_t(bufferIdx),
C.duk_size_t(size),
C.duk_size_t(length),
C.duk_uint_t(flags),
)
}
// See: http://duktape.org/api.html#duk_push_c_lightfunc
func (d *Context) PushCLightfunc(fn *[0]byte, nargs, length, magic int) int {
return int(C.duk_push_c_lightfunc(
d.duk_context,
fn,
C.duk_idx_t(nargs),
C.duk_idx_t(length),
C.duk_int_t(magic),
))
}
// See: http://duktape.org/api.html#duk_push_error_object_va
func (d *Context) PushErrorObjectVa(errCode int, format string, values ...interface{}) {
__str__ := C.CString(fmt.Sprintf(format, values...))
C._duk_push_error_object(d.duk_context, C.duk_errcode_t(errCode), __str__)
C.free(unsafe.Pointer(__str__))
}
// See: http://duktape.org/api.html#duk_push_external_buffer
func (d *Context) PushExternalBuffer() {
C._duk_push_external_buffer(d.duk_context)
}
/**
* Unimplemented.
*
* CharCodeAt see: http://duktape.org/api.html#duk_char_code_at
* CreateHeap see: http://duktape.org/api.html#duk_create_heap
* DecodeString see: http://duktape.org/api.html#duk_decode_string
* Free see: http://duktape.org/api.html#duk_free
* FreeRaw see: http://duktape.org/api.html#duk_free_raw
* GetCFunction see: http://duktape.org/api.html#duk_get_c_function
* GetMemoryFunctions see: http://duktape.org/api.html#duk_get_memory_functions
* MapString see: http://duktape.org/api.html#duk_map_string
* PushSprintf see: http://duktape.org/api.html#duk_push_sprintf
* PushVsprintf see: http://duktape.org/api.html#duk_push_vsprintf
* PutFunctionList see: http://duktape.org/api.html#duk_put_function_list
* PutNumberList see: http://duktape.org/api.html#duk_put_number_list
* Realloc see: http://duktape.org/api.html#duk_realloc
* ReallocRaw see: http://duktape.org/api.html#duk_realloc_raw
* RequireCFunction see: http://duktape.org/api.html#duk_require_c_function
* ConfigBuffer see: http://duktape.org/api.html#duk_config_buffer
* GetBufferData see: http://duktape.org/api.html#duk_get_buffer_data
* StealBuffer see: http://duktape.org/api.html#duk_steal_buffer
* RequireBufferData see: http://duktape.org/api.html#duk_require_buffer_data
* IsEvalError see: http://duktape.org/api.html#duk_is_eval_error
*/
|