1

I try to implement a very simple example to return values from an array. My example seems simple but I couldn't understand why it is not working:

This my code in C++

static int results[20];

extern "C" {
    void setValue(int index, int value {
        results[index] = value;
    }
    int getValue (int index) {
        return results[index];
    }
};

My code in .html:

Module.ccall('setValue',null,['number','number'],1,1);
var val = Module.ccall('getValue','number',['number'],1);

My command for compiling:

emcc --bind -o face_quick_example.js face_quick_example.cpp -s EXPORTED_FUNCTIONS="['_setValue','_getValue']"

I checked the tutorial and some stackoverflow answers, but I couldn't it do working

1 Answer 1

4

When using ccall the arguments to be passed to the C function must be inside an array, so your JavaScript for calling setValue and getValue should be:

Module.ccall('setValue', null, ['number', 'number'], [1, 1]);
var val = Module.ccall('getValue', 'number', ['number'], [1]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.