Iter Ator
Iter Ator

Reputation: 9289

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;
    //...
}

Upvotes: 11

Views: 636

Answers (1)

Y. Verzun
Y. Verzun

Reputation: 109

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.

Upvotes: 1

Related Questions