Symisc Systems

Libcox C/C++ API Reference - Setting The Result Of a Foreign Command


Star Follow @symisc

Syntax

int libcox_result_int(libcox_context *pCtx,int iValue);

int libcox_result_int64(libcox_context *pCtx,libcox_int64 iValue);

int libcox_result_bool(libcox_context *pCtx,int iBool);

int libcox_result_double(libcox_context *pCtx,double Value);

int libcox_result_null(libcox_context *pCtx);

int libcox_result_string(libcox_context *pCtx,const char *zString,int nLen);

int libcox_result_string_format(libcox_context *pCtx,const char *zFormat,...);

int libcox_result_value(libcox_context *pCtx,libcox_value *pValue);


Set the return value of a foreign command.

Description

These routines are used by the xCmd() callback that implement foreign libcox command to return their computation result. See libcox_register_command() for additional information.

These functions work very much like the libcox_value_* family of functions used to populate libcox_value.

The libcox_result_int() interface sets the result from an application-defined command to be an integer value specified by its 2nd argument.

The libcox_result_int64() interface sets the result from an application-defined command to be a 64-bit integer value specified by its 2nd argument.

The libcox_result_double() interface sets the result from an application-defined command to be a floating point value specified by its 2nd argument.

The libcox_result_bool() interface sets the result from an application-defined command to be a Boolean value (Only zero is assumed FALSE) specified by its 2nd argument.

The libcox_result_null() interface sets the return value of the application-defined command to be NULL (default return value).

The libcox_result_value() interface sets the result from an application-defined command to be a copy of the libcox_value obtained by a prior successful call to libcox_context_new_scalar() or libcox_context_new_array(). This is how arrays are returned from foreign commands.

The libcox_result_string() interface sets the result from an application-defined command to be a string value whose content is specified by the 2nd argument.

Note that libcox_result_string() accepts a third argument which is the length of the string to append. If the nLen argument is less than zero, then zString is read up to the first zero terminator. If nLen is non-negative, then it is the maximum number of bytes read from zString.

libcox_result_string_format() is a work-alike of the "printf()" family of commands from the standard C library which is used to append a formatted string.

Note that the printf() implementation in the libcox core is based on the one found in the SQLite3 source tree.

The libcox_result_string() and libcox_result_string_format() interfaces write their result to an internal buffer which grow automatically by successive calls to one of them (An append operation). That is, previously written data is not erased by the new call.


Parameters

pCtx

Call Context.


Return value

LIBCOX_OK is returned on success. Any other return value indicates failure.


See also

Obtaining Libcox Object Values, Populating Object Values.