Howto:Extend Nasal: Difference between revisions

Jump to navigation Jump to search
m
Line 82: Line 82:
The arguments to the function are passed in in the args array. The number of arguments is passed via argc (this is basically consistent with the standard signature of main in C/C++).
The arguments to the function are passed in in the args array. The number of arguments is passed via argc (this is basically consistent with the standard signature of main in C/C++).


So, if you know that you require a certain number of arguments, you can also directly check argc for matching your requirements and show an error message, or throw an exception using naRuntimeError().
So, if you know that you require a certain number of arguments, you can also directly check argc for matching your requirements and show an error message, return nil, or throw an exception using naRuntimeError():
 
// Throw an error from the current call stack.  This function makes a
// longjmp call to a handler in naCall() and DOES NOT RETURN.  It is
// intended for use in library code that cannot otherwise report an
// error via the return value, and MUST be used carefully.  If in
// doubt, return naNil() as your error condition. Works like
// printf().
void naRuntimeError(naContext c, const char* fmt, ...);
 


The "me" reference is set if the function was called as a method call on an object (e.g. object.your_function() instead of just your_function(), in which case "me" would be set to the object).
The "me" reference is set if the function was called as a method call on an object (e.g. object.your_function() instead of just your_function(), in which case "me" would be set to the object).
2,561

edits

Navigation menu