Howto:Extend Nasal: Difference between revisions

Jump to navigation Jump to search
m
m (some more examples, untested/uncompiled at the moment)
Line 92: Line 92:


And then get the appropriate value out with things like naNumValue(), naStr_data(), etc...
And then get the appropriate value out with things like naNumValue(), naStr_data(), etc...
So, if were now to change the interface of our earlier "cool" function in the example, to only return "cool" if we are passed at least one numerical parameter, and otherwise return "uncool", it could look like this:
static naRef f_cool (naContext c, naRef me, int argc, naRef* args)
{
    const char* cool="cool";
    const char* uncool="uncool";
    const char* res;
    naRef retval;
    if (isNaNum(args[0]))
      result=cool;
    else
      result=uncool;   
    return naStr_fromdata(retval, result, strlen(result) );;
}


= Creating Nasal Data Structures =
= Creating Nasal Data Structures =
2,561

edits

Navigation menu