[erlang-questions] using strings with NIF

Jason Frame <>
Wed Dec 9 06:47:29 CET 2009


Thats not quite what I want as that will return a ERL_NIF_TERM. I have
a ERL_NIF_TERM from the passed in function argument which should
contain the string somehow and I need to decode that into a c style
string ie. an array of char.

On Wed, Dec 9, 2009 at 2:25 PM, Jarrod Roberson <> wrote:
> On Tue, Dec 8, 2009 at 11:08 PM, Jason Frame <> wrote:
>> Hi,
>>
>> I am trying to use a string as an argument with NIF. I can't work out
>> how to extract the string on the c side though. Using a int is quite
>> simple with the enif_get_int function but there doesn't seem be a
>> similar function for strings. I have tried encoding a tuple with
>> term_to_binary then using erl_decode and then use erl_element and the
>> associated functions to extract the string. But it fails with a
>> segfault and I'm sure there is probably a better way to do this.
>
> I could be wrong, but I would think that
>
> ERL_NIF_TERM enif_make_list(ErlNifEnv* env, unsigned cnt, ...)
>
> is what you want, since in Erlang "strings" are just lists of bytes.
>


More information about the erlang-questions mailing list