iotjs icon indicating copy to clipboard operation
iotjs copied to clipboard

Add support for JavaScript Array in binding layer

Open yichoi opened this issue 9 years ago • 9 comments

  • [ ] Add array support in binding layer
    • [x] create array / check if object is array / ...
    • [ ] add support to easily iterate over array elements (esp. for sparse array, maybe in jerry?)
    • [ ] ... (TBD)
  • [ ] Use array support in IoT.js
    • [ ] in i2c module, many APIs should use array as input parameter or callback argument
    • [x] in buffer module, enable new Buffer(array)
    • [x] in http_incoming module, IncomingMessage.headers should be array type
    • ... (TBD)

yichoi avatar Oct 13 '16 07:10 yichoi

I think it will be better to support more APIs in binding layer. For example, push(add) and pop(remove) for numbered index and named index will be very helpful.

nova0821 avatar Oct 13 '16 11:10 nova0821

I made a PR for array creating and checking for char array. Please see #460.

glistening avatar Oct 14 '16 06:10 glistening

Is there any progress in this issue? If anyone did not made a progress, I want to handle it.

RedCarrottt avatar Nov 23 '16 13:11 RedCarrottt

We intentionally don't put more time into this issue since we don't want to make APIs bigger. We want to keep APIs minimal.

glistening avatar Nov 24 '16 01:11 glistening

All the issues posted are in progress or in pending for some reason. Therefore I recommend you suggest your proposal in issue. You can refer to the guide in Development-Process, especially in Feature development process.

glistening avatar Nov 24 '16 01:11 glistening

buffer module, enable new Buffer(array) - done in http_incoming module, IncomingMessage.headers should be array type - landed in #776 add support to easily iterate over array elements - We want to keep the API minimal. Let's discuss this item when we need this API.

glistening avatar Apr 24 '17 02:04 glistening

@glistening Right now, there is no support to easily iterate over JS array elements on the C side. This feature will be extremely useful in a OCF Things SDK I am currently working on. Is support for this planned in the near future, or will it not be supported to keep APIs minimal?

Note - While it would be great to have support in binding for Array Iteration, there are some workarounds which can be used right now. Currently I convert the array to object on the JS side, pass the object to C side, iterate over the elements of the object and create a new array on the C side. For example, this Array - ['a','b','c'] Becomes - { 0: 'a', 1: 'b', 2: 'c' }

akhilkedia avatar Sep 01 '17 08:09 akhilkedia

@akhilkedia you can call jerry_get_array_length and jerry_get_property_by_index directly until the IoT.js binding hasn't done.

LaszloLango avatar Sep 01 '17 13:09 LaszloLango

@LaszloLango Thanks!

akhilkedia avatar Sep 03 '17 16:09 akhilkedia