Updating the original reference of a variable


#1

I’m working on a library similar to what DL does and I’m having a
problem with implementing variables that are to be passed as pointers.
I have all the C side code working, the problem is updating the original
variable with a modified value (for example you are calling a function
that takes two int* and sets their values based on some initilization).
My setup for passing the call along to the C function is to splat the
parameters into an array and pass the array and the function name into
the C layer which then makes the call into the loaded library.

def dispatch(ruby_name, *args)
self.class.fl_call_function(@function_handles[ruby_name], args)
end

If in the C layer I modify the value of one of the array elements that
value is changed when I return but I don’t have a way of propogating
that array element’s value to the original variable that was passed in.
Is there any way to get the object containing the variable (maybe by
using the object_id?) that was passed in and then use that to set a new
value for the variable?

David K.


#2

On Dec 3, 2005, at 11:36 PM, David K. wrote:

If in the C layer I modify the value of one of the array elements
that value is changed when I return but I don’t have a way of
propogating that array element’s value to the original variable
that was passed in. Is there any way to get the object containing
the variable (maybe by using the object_id?) that was passed in and
then use that to set a new value for the variable?

David K.

No. Consider changing the mapping into one that returns multiple
values, or do something like

v = []
def fun(x)
x << result
end

fun(v)

do stuff with v[0]


#3

On 12/3/05, David K. removed_email_address@domain.invalid wrote:

I’m working on a library similar to what DL does and I’m having a
problem with implementing variables that are to be passed as pointers.
I have all the C side code working, the problem is updating the original
variable with a modified value (for example you are calling a function
that takes two int* and sets their values based on some initilization).
My setup for passing the call along to the C function is to splat the
parameters into an array and pass the array and the function name into
the C layer which then makes the call into the loaded library.

Ruby’s variables don’t work that way.

-austin