You should use the following: static int BB_NsvSet(const char *nsvString, const char *keyString, const char *valueString) { Tcl_Obj *o[4]; o[0]=Tcl_NewStringObj("nsv_set",7); o[1]=Tcl_NewStringObj(nsvString,-1); o[2]=Tcl_NewStringObj(keyString,-1); o[3]=Tcl_NewStringObj(valueString,-1);
Tcl_IncrRefCount(o[0]); Tcl_IncrRefCount(o[1]); Tcl_IncrRefCount(o[2]); Tcl_IncrRefCount(o[3]); Tcl_EvalObjv(interp,4,&o[0],0); Tcl_DecrRefCount(o[0]); Tcl_DecrRefCount(o[1]); Tcl_DecrRefCount(o[2]); Tcl_DecrRefCount(o[3]); } This one uses Tcl objects (it won't work with 7.6 Tcl :), the main advantage is that it will set strings with quotes - like BB_NsvSet("a","b","\""); Your code will fail with this one. Don't know about speed performance though. Andrew Piskorski wrote: > 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 > > > -- WK "UTF-8 has a certain purity in that it equally annoys every nation, and is nobody's default encoding." -- Andy Robinson