Folks, has anyone implemented a C NSV API, or does anyone plan to?
Clearly the right thing to do would be to move the functinality in
aolserver/nsd/tclvar.c into C API functions, and re-implement the nsv
Tcl commands to that C API.
But since I needed to use some nsv commands from C, and I was in a
hurry, I just kludged up my own C NSV functions using Ns_TclEval, like
the example below.
So has anybody done this in a less kludgy fashion? Also, any guesses
as to what sort of performance hit I'm taking by using Ns_TclEval?
static int
BB_NsvSet(const char *nsvString,
const char *keyString, const char *valueString)
{
static const char func_name[] = "BB_NsvSet";
Ns_DString dsScript;
Ns_DString dsResult;
int rc;
Ns_DStringInit(&dsScript);
Ns_DStringInit(&dsResult);
/*
* The key and value may each have embedded whitespace, as we are
* surronding them with double quotes. But we asumme that the nsv
* array name will always be one word.
*/
Ns_DStringVarAppend(&dsScript, "nsv_set ", nsvString, " ",
"\"", keyString, "\"", " ",
"\"", valueString, "\"", NULL);
rc = Ns_TclEval(&dsResult, NULL, dsScript.string);
Ns_DStringFree(&dsScript);
Ns_DStringFree(&dsResult);
return rc;
}
--
Andrew Piskorski <[EMAIL PROTECTED]>
http://www.piskorski.com