EzDevInfo.com

duktape

Duktape - embeddable Javascript engine with a focus on portability and compact footprint

Can Duktape make http requests

I have a very simple duktape plugin running embedded in another program. Simple stuff works, but I am not sure how to make HTTP requests. Is it even possible to make HTTP Request from within a Duktape VM?


Source: (StackOverflow)

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 method of just calling

duk_throw(duk_context);

as my signal handler is not very reliable. I'm guessing the engine is in a bad state at that point so can't carry on.

Anyone have any ideas?

I thought about setting a flag somewhere, but no sure how to do this cleanly.

Thank you

Matt


Source: (StackOverflow)

Advertisements

use duktape on ARM to play audio

I would like to use Duktape on my embedded device (ARM processor) to execute Javascript which will download a music stream and play it.

Question 1: Has anyone done that before? Is that possible at all (sound ouput)?

Question 2: If it is possible then I would also like to grab the PCM output and redirect it (not play on the SoundDriver directly). A pointer where to start would be great.

Thanks in advance for any help getting started folks!


Source: (StackOverflow)

Postgres equivalient in SQLite to search JSON object

I have got the below Postgres Query:

db.queryAsync('SELECT _id, value FROM ' + store + ' WHERE (value->>$1)=$2;', [index, id]);

I want to write the same in SQLite. I have created the value field as TEXT type, but then not sure how to query. I am using SQLite and JavaScript running on Duktape.


Source: (StackOverflow)

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


Source: (StackOverflow)

How to wrap C++ classes with Duktape

I am playing around with Duktape as a replacement to v8. Skimmed through the docs and managed to call C functions from Javascript and vice-versa. However it is not clear to me how to proceed when you need to access C++ classes from JavaScript in a similar way to v8. Could someone put together a very simple example illustrating this?

Thanks!


Source: (StackOverflow)

export c++ class to duktape

say I have a c++ class Point

class Point {
public:
    Point();
    Point(float x, float y);
    ~Point();

    float X;
    float Y;

};

I'd like to add javascript functionality to it and chose duktape.

is it possible to reuse this class in javascript? say

var p = new Point(1.23, 4.56);

I have been reading the duktape documentation and it only says how to reuse functions inside javascript.


Source: (StackOverflow)

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 this reason, I need to be able to redeclare self as a JSComponent or Script. Digging around in the standard TypeScript libraries, I stumbled on the following, which I've found no documentation on anywhere:

/// <reference no-default-lib="true"/>

Adding this to a d.ts to be included half solves the problem:

/// <reference path="./Atomic.d.ts" />
/// <reference no-default-lib="true"/>

// Redeclare self as a JSComponent
declare var self: Atomic.JSComponent;

I can now reference this in my TS files, and use self as a JSComponent. However I can no longer use standard classes such as Object and Array-in this or any other TS file in my project.

Is there a way to use no-default-lib for just this section of code, to replace the definition of self? Alternatively, is there another way to achieve this re-declaration?


Source: (StackOverflow)

Duktape - catch errors in C

I just started using Duktape in my C++ framework today, and I've read the entire api without being able to understand how do i catch errors. I found some clues about an error object that is put on the stack However, every time there is an error (like an invalid javascript syntax for example), everything goes crazy and i get a SEGFAULT.

I'm currently evaluating some js lines using the duk_eval function

Here's my lines of code :

duk_push_string(ctx,"pouet");
duk_eval(ctx);

ctx is the base context that you provide when creating duktape heap

Using try-catch doesn't catch anything

Any idea?

Thanks in advance


Source: (StackOverflow)

disable transcendentals in duktape

I like duktape. Good job creating it!

But, when working with resource limited devices, there might be times when I would like to disable the transcendental functions in Javascript. I know this breaks language compatibility. But, for an embedded device whereby I control the environment, this is a reasonable trade-off.

How do I disable transcendentals in duktape to conserve space? If I can't do this, then would it be helpful if I created the ability to do this and issued a git pull request?

Thanks.

-brad walker


Source: (StackOverflow)

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, "global_array"); duk_pop(ctx);

but how I can get value by key from global later?

P.S.: Sorry for my English.


Source: (StackOverflow)

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?


Source: (StackOverflow)

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: "dev4", on: 13, off: 17 }
];

duktape has great documentation, but I can not seem to find any example of what I am trying to accomplish.

I have managed to read a single dimension array. (Not sure if it is the best or proper way to to do it)

// var one_dim = [ "hello", "world", "single", "dimension", "array" ] ;

void init_one_dimension(void) {

  duk_get_prop_string(ctx, -1, "one_dim");

  if(duk_is_array(ctx, -1)) {
    printf("Found array\n");
    duk_enum(ctx, -1, DUK_ENUM_ARRAY_INDICES_ONLY); 

    while (duk_next(ctx, -1 , 0 )) {

      duk_get_prop_index(ctx, -1, 0);
      duk_get_prop_string(ctx, -4, duk_get_string(ctx, -1));
      printf("%s\n", duk_get_string(ctx, -1));
      show_stack(ctx, "STACK");

      duk_pop(ctx); // get_prop_string
      duk_pop(ctx); // get_prop_index
      duk_pop(ctx); // duk_next
    }

    duk_pop(ctx); // duk_enum
    duk_pop(ctx); // duk_get_prop_string
  }
}

Multi-dimensional arrays escape me. Any help would be appreciated.


Source: (StackOverflow)

require causes an error in duktape

I am using duktape for embedding javascript, but using require always causing an error:

int main(){
  duk_context *ctx = duk_create_heap_default();
  duk_peval_file(ctx, "example.js");
  printf("file load err %s", duk_safe_to_string(ctx, -1));
  duk_destroy_heap(ctx);
}

example.js

var mylib = require("mylib")
print (mylib.hello)

mylib.js

exports.hello = "Hello"

Error:

file load err TypeError: not callable

Stack dump says:

duk_js_call.c:682
require native strict preventsyield
eval example.js:1 preventsyield

Source: (StackOverflow)

Keeping UINT64 values in V8

I'm looking to integrate a scripting engine in my C/C++ program. Currently, I am looking at Google V8.

How do I efficiently handle 64 bit values in V8? My C/C++ program uses 64 bit values extensivly for keeping handlers/pointers. I don't want them separatelly allocated on the heap. There appears to be a V8::External value type. Can I assign it to a Javascript variable and use it as a value type?

function foo() {

   var a = MyNativeFunctionReturningAnUnsigned64BitValue();

   var b = a; // Hopefully, b is a stack allocated value capable of
              // keeping a 64 bit pointer or some other uint64 structure.

   MyNativeFunctionThatAcceptsAnUnsigned64BitValue(b);

}

If it is not possible in V8, how about SpiderMonkey? I know that Duktape (Javascript engine) has a non Ecmascript standard 64 bit value type (stack allocated) to host pointers, but I would assume that other engines also wants to keep track of external pointers from within their objects.


Source: (StackOverflow)