Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an own struct_info.json? (emscripten)

I would like to port a C library. There is a really short tutorial about it here: Interacting with code

I need to create a struct using javascript, and return a pointer to it. I looked into the libraries, which are already ported. My code looks like this:

var ptr = _malloc({{{ C_STRUCTS.MyStruct.__size__ }}});

{{{ makeSetValue('ptr', C_STRUCTS.MyStruct.attr, '0', 'i8') }}};

It does not work, because emscripten does not know about MyStruct.

My library definition is added to the project using --js-library But I don't know, how to add a struct definition (struct_info.json)

In the C code, I have:

struct MyStruct {
    int8_t attr;
    //...
}
like image 370
Iter Ator Avatar asked Dec 11 '16 22:12

Iter Ator


1 Answers

You should create C but not JS struct. For example:

var st_t = new ctypes.StructType("st_t",
        [ { "self": ctypes.PointerType(ctypes.void_t) },
        { "str": ctypes.PointerType(ctypes.char) },
        { "buff_size": ctypes.size_t },
        { "i": ctypes.int },
        { "f": ctypes.float },
        { "c": ctypes.char } ]);  

Hope it will help.

like image 144
Y. Verzun Avatar answered Sep 28 '22 02:09

Y. Verzun