Questions tagged [duktape]

Duktape is a highly optimized embedded JavaScript engine for C/C++

Duktape is an MIT-licensed embedded engine for /.
Its main features are :

  • Embeddable, portable, compact:
    • 200kB code
    • 46kB startup RAM (x86, default options)
    • 22kB startup RAM (x86, lowmem options)
    • 42kLoC source (excluding comments etc)
    • Can run on platforms with 256kB flash and 96kB system RAM
  • Ecmascript E5/E5.1 compliant, some features borrowed from E6 draft
  • Built-in regular expression engine
  • Built-in Unicode support
  • Minimal platform dependencies
  • Combined reference counting and mark-and-sweep garbage collection with finalization
  • Custom features like coroutines, built-in logging framework, and built-in CommonJS-based module loading framework
  • Property virtualization using a subset of Ecmascript E6 Proxy object
93 questions
1
vote
2 answers

duktape closure registration

I have C++ project and I'm using duktape JS library. I need to register global function in JS and save pointer to object as closure data with this function, so I can access this pointer when function is called. I know how to do this in lua c…
user1204080
1
vote
1 answer

How do I best put a processing limit on Duktape's engine?

I realize the use of DUK_USE_EXEC_TIMEOUT_CHECK is experimental (as of 1.5) but I'm unclear how to best utilize it. What I'm trying to do is put a hard limit on opcode execution to prevent bad scripts from killing my process via infinite loops,…
mark
  • 5,269
  • 2
  • 21
  • 34
1
vote
1 answer

Duktape/C array element accessors

I am trying to implement something like a HTMLCollection which is an array that can lose/gain elements without JS action. duk_push_object(ctx); duk_push_string(ctx, "length"); duk_push_c_function(ctx, my_length_getter, 1); duk_def_prop(ctx, -3,…
1
vote
1 answer

How can I read a file from JavaScript code running in Duktape?

I am trying to port some code from Node.js to Duktape - does Duktape have a function equivalent to Node's fs.readFileSync?
user200783
  • 13,722
  • 12
  • 69
  • 135
1
vote
1 answer

Construct variadic template argument list

Say i have the following scenario: namespace detail { using duk_c_function_t = std::function; template duk_ret_t…
tubberd
  • 540
  • 5
  • 15
1
vote
1 answer

How to parse recursive json data in duktape?

I am trying to parse an recursive data structure with duktape and seem to have an error somewhere. Since i am new to the duktape library and the examples are not clear on this situation, i thought i could ask the crowd. The data: { "type":…
scones
  • 3,317
  • 23
  • 34
1
vote
1 answer

Should duktape be able to handle this nested assignment construct?

I'm using TypeScript to generate enum code that I'm running in a duktape interpreter: var NodeType; (function (NodeType) { NodeType[NodeType["none"] = 0] = "none"; NodeType[NodeType["text"] = 1] = "text"; })(NodeType || (NodeType =…
Ben Flynn
  • 18,524
  • 20
  • 97
  • 142
1
vote
1 answer

Is "require()" safe in a sandbox?

I'm building a sandboxed duktape application. The sanboxing doc (https://github.com/svaarala/duktape/blob/master/doc/sandboxing.rst) advises to remove the default require() implementation. I'm not clear why that is necessary. It seems that require()…
Oliver Crow
  • 328
  • 2
  • 7
1
vote
2 answers

Duktape get array value

I can paste array with values by key in global like this: duk_push_global_object(ctx); duk_idx_t arr_idx = duk_push_array(ctx); duk_push_string(ctx, "string by key"); duk_put_prop_string(ctx, arr_idx, "key"); duk_put_prop_string(ctx, -2,…
Nikeron
  • 11
  • 2
1
vote
1 answer

How can I replace the type of self in TypeScript?

I'm working in an embedded JavaScript engine (based on duktape). In this context, "self" is not of type Window but either of type Script or JSComponent. Using typescript, compilation causes errors when using members of these classes on self. For…
FlintZA
  • 872
  • 1
  • 11
  • 22
1
vote
1 answer

duktape: "TypeError: not callable"

duk> (function digits(x) { var _x = Math.abs(x); _x = Math.log10(_x); return _x ;} ) (10) TypeError: not callable duk_js_call.c:682 digits input:1 global input:1 preventsyield
black_13
  • 169
  • 1
  • 7
1
vote
3 answers

Any way to get proper C++ stack unwinding when duktape throws an error?

Is there currently any way to get duktape to properly unwind the C++ stack (calling all appropriate destructors, etc.) when an error is encountered in duktape? I know that Lua (for example) has the capability to do this by switching from the use of…
Scott
  • 13
  • 1
  • 5
1
vote
0 answers

SIGINT handelling in Duktape

anyone know how I can handle SIGINT (interrupt signals) when working with Duktape? I would like to throw an exception that I can catch in the javascript when the user interrupts using CTRL+C. I have a function to catch the signal, but my current…
Matt
  • 134
  • 15
1
vote
1 answer

DukTape Display JavaScript Canvas on GLUT Window

I managed to get DukTape working in my GLUT project (it is able to run inline javascript with duk_eval_string();). Is it possible to display a static html canvas with javascript graphics in a C++ GLUT window using DukTape?
1
vote
1 answer

How do I read a script array into duktape?

I'm new to duktape and trying to read a config from a script file: var config = [ { ready: true, name: "dev1", on: 8, off: 9 }, { ready: true, name: "dev2", on: 10, off: 11 }, { ready: true, name: "dev3", on: 18, off: 21 }, { ready: true, name:…
nm156
  • 11
  • 3