Erlang: Interfacing with Xalan: port driver or nif

2019-07-04 20:49发布

I'd like to get a real XSLT processor working with erlang. Which would be the best interface, nif or port driver? According to the nif documentation, nif calls block the runtime, so they should not take long. Is processing a long xml document too long?

Also, I'd like to allow erlang callbacks during the transformation. Does that seem possible? Possible with nif but not port drivers or vice versa?

I've never written any C, so I figured this would be good introduction. Xalan is C++. I assume nif can work with that, right?

1条回答
成全新的幸福
2楼-- · 2019-07-04 21:16

I would recommend building a port driver.

The NIF facility is a way to add new built-in functions to the language and speed up things that would be too slow to implement in pure Erlang. NIFs are considered experimental anyway, so the interface might change radically in future releases.

Writing a port driver means implementing a C (or C++) shared library that behaves like a whole erlang process. This allows for greater flexibility as you can communicate with other processes while transforming a document (callbacks...), etc.

It doesn't even have to be a driver. If you don't pass lots of data between your port program and other Erlang code you might consider writing a plain port instead (it's easier).

查看更多
登录 后发表回答