Re: [tcljava-user] Porting Tcl_ObjSetVar2 Tcl C API Invocations to TclJava
Brought to you by:
mdejong
From: Tom P. <tpo...@ny...> - 2016-06-03 21:44:33
|
Hi Brian, JTcl uses Java method overloading for most of the different combinations of Inter.setVar() for setting by varname as String or TclObject with a value of String or TclObject. See all of the various method signatures for Interp.setVar(). Same goes for Interp.setResult(), overloaded for a few primitive types, String, and TclObject. http://jtcl-project.github.io/jtcl/apidocs/tcl/lang/Interp.html -Tom On Fri, Jun 03, 2016 at 02:29:15PM +0000, Brian Brooks (US) wrote: > Hello TclJava/Jtcl Community, > > Thanks again for all the effort that has gone into the TclJava and JTcl projects! > > **QUESTION** > > Does TclJava/JTcl have an equivalent to Tcl_ObjSetVar2; documented here: https://www.tcl.tk/man/tcl/TclLib/SetVar.htm? > > If not, how might I work around this limitation? > > **CONTEXT OF QUESTION** > > We're using JTcl 2.8.0 on Windows and Linux. > > I'm porting some C code to Java. In the C code, a TCL command that returns two different TclObject values: > > 1. TclString is returned as the command's result using Tcl_SetObjResult. > 2. Tcl_NewByteArrayObj is returned in the "outargSomeByteArray" TCL command parameter using Tcl_ObjSetVar2. > > Here's some of the C TCL command code I'm porting to TclJava... > > --snip-- > Tcl_CreateObjCommand( pInterp->interp, "read_string", cmd_read_string, (ClientData)pInterp, NULL ); > --snip-- > > ///////////////////////////////////////////////////////////////////// > // cmd_read_string > // > // TCL syntax is: > // read_string outargSomeByteArray > // returns <returnCode> either "OK", "TIMEOUT", "OVERFLOW", "MAIL", "MAINT", or "UNKNOWN" > ///////////////////////////////////////////////////////////////////// > > int cmd_read_string( ClientData clientData, Tcl_Interp * interp, int objc, Tcl_Obj * CONST objv[] ) { > > // ------------- SNIPPED CODE THAT DOES SOMETHING -- > > // return #1 command response > switch( rc ) { > case TCL_VALID_STRING: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "OK", -1 ) ); > break; > case TCL_TIMEOUT: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "TIMEOUT", -1 ) ); > break; > case TCL_OVERFLOW: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "OVERFLOW", -1 ) ); > break; > case TCL_PENDING_MAIL: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "MAIL", -1 ) ); > break; > case TCL_MAINT_MODE: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "MAINT", -1 ) ); > break; > case TCL_PENDING_CMD: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "COMMAND", -1 ) ); > break; > case TCL_PENDING_SYS_CALLBACK: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "SYS_CALLBACK", -1 ) ); > break; > default: > Tcl_SetObjResult( interp, Tcl_NewStringObj( "ERROR", -1 ) ); > break; > } > > // return #2 outargSomeByteArray > Tcl_ObjSetVar2( interp, objv[ 1 ], NULL, Tcl_NewByteArrayObj( (unsigned char *)someString, someStringLength ), 0); > > return( TCL_OK ); > } > > In the Java port, I've got code like... > > class cmd_read_string implements tcl.lang.Command { > > // --snip-- > > @Override > public void cmdProc(Interp interp, TclObject[] objv) throws TclException { > > // ------------- SNIPPED CODE THAT DOES SOMETHING -- > > // return #1 command response > switch (rc) { > case DefineConstants.TCL_VALID_STRING: > interp.setResult("OK"); > break; > case DefineConstants.TCL_TIMEOUT: > interp.setResult("TIMEOUT"); > break; > case DefineConstants.TCL_OVERFLOW: > interp.setResult("OVERFLOW"); > break; > case DefineConstants.TCL_PENDING_MAIL: > interp.setResult("MAIL"); > break; > case DefineConstants.TCL_MAINT_MODE: > interp.setResult("MAINT"); > break; > case DefineConstants.TCL_PENDING_CMD: > interp.setResult("COMMAND"); > break; > case DefineConstants.TCL_PENDING_SYS_CALLBACK: > interp.setResult("SYS_CALLBACK"); > break; > default: > interp.setResult("ERROR"); > break; > } > > // return #2 outargSomeByteArray > // How to port from C to TclJava? I see there is a TclByteArray.newInstance for the Tcl_NewByteArrayObj > // but TclJava seems to lack Tcl_ObjSetVar2 support. > // Tcl_ObjSetVar2( interp, objv[ 1 ], NULL, Tcl_NewByteArrayObj( (unsigned char *)someString, someStringLength ), 0); > > } > > } > > Sincerely, > Brian Brooks > Sr Software Engineer > Duluth, GA 30096 > > ------------------------------------------------------------------------------ > What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic > patterns at an interface-level. Reveals which users, apps, and protocols are > consuming the most bandwidth. Provides multi-vendor support for NetFlow, > J-Flow, sFlow and other flows. Make informed decisions using capacity > planning reports. https://ad.doubleclick.net/ddm/clk/305295220;132659582;e > _______________________________________________ > tcljava-user mailing list > tcl...@li... > https://lists.sourceforge.net/lists/listinfo/tcljava-user -- Tom Poindexter tpo...@ny... |