开发者

Adobe Alchemy returning C data structures

I have lexer/parser (Generated from an ANTLR grammar file) which (for performance reasons) I have compiled to C code which will be included into my actionscript project using Adobe Alchemly.

The parser will generate an abstract syntax tree (In C) from an input string (passed from Actionscript) - I wish to return the C AST back into actionscript for further开发者_StackOverflow中文版 processing. How can I convert the tree structure of the AST to a format which I can return to actionscript?

Thanks,


Unfortunately you can't just send a C data structure across. You've got three options, in increasing order of madness:

  1. Serialize the data on the C side and reconstitute it on the AS3 side.
  2. Pack up the data into Objects and return those.
  3. Pass a pointer and size back to AS3 and pull out the data from Alchemy's ram ByteArray.

I only include #3 for completeness-- I think it would be crazy to try it for any kind of complex data structure. The code would be fragile. Following pointers would be clunky. Bleah.

For #2 you could use dynamic Objects (via AS3_Object) or concrete ones (via AS3_Get, AS3_New). This is fairly complex code also and not so fast. Can be hard to maintain.

For #1, the type of serialization is what matters. You could have your C code render the structures to a binary 'file', return that, and have your AS3 parse the file format via ByteArray. Or you could render it to XML and have AS3's XML class parse it. This has the benefit of being fairly fast (since XML is implemented natively), at least on the de-serialization end. If you have a fast XML renderer on the C side (or, ahem, sprintfs), its not so bad.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜