Muppet <[EMAIL PROTECTED]> writes:
>Dirk Koopman said:
>> So how do I find them and then set them (probably thru DynaLoader)? They
>> are (at least for now) just simple ints.
>
>You could use tie'd scalars for this.  Create your perl-level variables from
>perl, passing the c names to your tie, and tie them all to the same class.  In
>the FETCH and STORE routines, do the dlsym lookup and load or store the value.
> If they'll be changed a lot, you might instead cache their addresses after
>doing the dlsym lookup in TIESCALAR.

If you can know the names of variables at XS build time a trick that works 
well is #define to produce something that looks like a function

#define setFoo(x) foo = (x)

MODULE ...

void setFoo(int x)

Then normal XS wrapper gets created.

and perl code can say
  setFoo(42);

>
>I've used this trick to tie a perl hash-like object to a fancy C key-query
>object, and it didn't take a lot of code.  I have *not* done it for scalars,
>but i'm guessing it wouldn't be too hard.

For scalars it is possible to do direct MAGIC get/set with a bit less 
overhead than a full tie.

But if you have to lookup names at run time then tying ONE hash to 
the XS code is a good plan so that 

   $tiedHash{varname} = 42;

Calls STORE passing key and value,
STORE does a dlsym() on the "key" gets a pointer and pokes value.


Reply via email to