Hi Massimo,
I created a dummy library which can load in a tclsh.
The code is attached.
This lib just create a new command called "ydotm" and does nothing
If you compile this code and create a shared library libtesttclapi.so (the
name is important), you can then call in a tclsh:
load libtesttclapi.so
puts [ydotm ok]
You should see:
processCmd called
Now that would be easier for getting this new command visible in a rvt
page, from this lib loaded in a TCL_Thread() from the RivetInitChild.
I hope it helps,
Thank you,
Brice.
On Tue, Jun 12, 2018 at 11:01 AM, Brice Hamon <[email protected]>
wrote:
> Hi Massimo.
>
> Yes it is relevant as it is a command name, and not a variable.
>
> I think I understands what's going on with the Thread.
>
> The thread has its own interpreter created de facto. So my command is
> known only from that interpreter, and not from the Rivet's main interpreter.
>
>
>
> On Tue, Jun 12, 2018 at 10:22 AM, Massimo Manghi <[email protected]>
> wrote:
>
>> In case I try to test this code I have a question: is the call to [ynet
>> new] relevant somehow? I guess it can be replaced by a function that
>> returns a random string
>>
>> -- Massimo
>>
>>
>> On 06/12/2018 01:40 PM, Brice Hamon wrote:
>>
>>> Hi Massimo,
>>>
>>> Ok we are getting somewhere.
>>>
>>> I started a TCL thread, which loads my lib, create a session and starts
>>> it, followed by a vwait forever.
>>>
>>> This worked. I see the readycmd procedure been called when all the c++
>>> code is happy.
>>>
>>> It is not that easy to explain so here is what I do in the
>>> RivetChildInit:
>>>
>>>
>>> set tid [thread::create]
>>>
>>> thread::send -async $tid {
>>>
>>> proc ::readycmd {} {
>>> puts [info commands]
>>> puts [namespace children ::]
>>> puts [info procs]
>>> }
>>>
>>> proc ::errorcmd {txt} {
>>> log ERROR "SB: $err"
>>> }
>>>
>>> # Opening the link
>>> if {[catch {load -global libThreadTclApi.so threadtclapi} err]}
>>> {
>>> puts "Error loading the libThreadTclApi.so library: $err"
>>> }
>>>
>>> # Creating a session
>>> set ::sess_ [ynet new]
>>> $::sess_ configure -daemon y1 -port 2002
>>> $::sess_ configure -readycmd ::readycmd
>>> $::sess_ configure -errorcmd ::errorcmd
>>> $::sess_ open
>>> vwait forever
>>> }
>>>
>>> This code works but still 2 things is happening:
>>>
>>> 1) If the proc readycmd is defined outside the thread's script, the
>>> library is not be able to call it and generates an error.
>>>
>>> 2) on the rvt page, I can't see the ::sess_ variable nor that I see my
>>> library's new command.
>>>
>>> So the there is still things not working as I was hoping they will.
>>>
>>> Thank you,
>>> Brice.
>>>
>>>
>>>
>> Firma il tuo 5 x mille all’Università di Parma e aiuta così i nostri
>> studenti che vogliono realizzare un’esperienza di studio all’estero –
>> Indica 00308780345 nella tua denuncia dei redditi.
>>
>
>
#include "tcl.h"
using namespace std;
// ----------------------------------------------------------------------------
// Tcl command callbacks
int
processCmd(ClientData cd, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
{
printf("processCmd called\n");
return TCL_OK;
}
void
deleteCmd(ClientData data)
{
printf("deleteCmd called\n");
return;
}
// ----------------------------------------------------------------------------
// Bsthreadtclapi_Init
// Package initialization procedure for the bsthreadtclapi package.
// Creates command 'bsnet'.
//
// NOTE: please do not change the name: it's defined by TCL from the library.
// ----------------------------------------------------------------------------
extern "C"
int Testtclapi_Init(Tcl_Interp *interp)
{
if (Tcl_InitStubs(interp, "8.6", 0) == NULL)
{
return TCL_ERROR;
}
if (Tcl_PkgRequire(interp, "Tcl", TCL_VERSION, 0) == NULL)
{
return TCL_ERROR;
}
// Creating a dummy command
Tcl_CreateObjCommand(interp,
"ydotm", // command name
processCmd, // command callback
NULL, // Clent data
deleteCmd); // delete command callback
Tcl_PkgProvide(interp, "testtclapi", "1.0");
return TCL_OK;
}
// ----------------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]