[ANN] emStructObj, a new struct conversion tool

21 views
Skip to first unread message

Mark Hahn

unread,
Mar 5, 2014, 5:02:17 PM3/5/14
to emscripte...@googlegroups.com
Check out https://github.com/mark-hahn/emStructObj.

This is a set of javascript functions to convert between C/C++ structs and JS objects (both ways) in emscripten converted code.  It can be used for debug print statements or for inspecting structs in the browser js console.  It is 100% javascript and no C code is needed.

This has barely begun and is useless for now but will have an alpha version in a day or two.  I'm announcing it now for two reasons.  One is to get feedback and ideas and the second reason is to find out if this already exists in some form.  I will reply to this post when it is ready to try.

Mark Hahn

unread,
Mar 5, 2014, 7:16:44 PM3/5/14
to emscripte...@googlegroups.com
I forgot to mention that it is useful for more than debugging.  Javascript functions can convert struct pointers in arguments to objects and can write objects into the heap as structs.


--
You received this message because you are subscribed to a topic in the Google Groups "emscripten-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/emscripten-discuss/Ux468UD2YWU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Alon Zakai

unread,
Mar 5, 2014, 8:30:31 PM3/5/14
to emscripte...@googlegroups.com
Won't you need people to define C structures in JS for this to work? Sounds like it will need to handle alignment issues too, unless the user is responsible? We have code for that in Runtime which can help.

- Alon



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

Mark Hahn

unread,
Mar 5, 2014, 9:18:34 PM3/5/14
to emscripte...@googlegroups.com
Won't you need people to define C structures in JS for this to work? 

Yes, you have to copy the struct definitions from headers file to a custom js file.  I find it easy myself but others may have problems with this.  In the future if anyone finds this useful a real parser could be added that would just read the .h file.

Sounds like it will need to handle alignment issues too, unless the user is responsible? 

It just has to match whatever emscripten generates and the user shouldn't have to worry about it.  I may be wrong.

 We have code for that in Runtime which can help.

Can you elaborate?  I would happily abandon this if there was already a solution.




Alon Zakai

unread,
Mar 5, 2014, 9:40:08 PM3/5/14
to emscripte...@googlegroups.com
There is Runtime.calculateStructAlignment which calculates the offsets of fields given the types of the fields, basically (it calculates padding and alignment and so forth). I was thinking that could help here perhaps. It would need some refactoring most likely.

- Alon



Mark Hahn

unread,
Mar 5, 2014, 11:12:42 PM3/5/14
to emscripte...@googlegroups.com
calculateStructAlignment in runtime.js looks really useful and it is available at run time!  :-)  

There are actually several related routines that might help. There is a lot of code in there.  It looks like emStructObj could call the routines with no refactoring.  I had no idea this was such a problem.  

Thanks mucho for the reference.  

Reply all
Reply to author
Forward
0 new messages