Forum: Ruby Updating the original reference of a variable

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E2bbe31fb94e92f5f404c5cb550c371f?d=identicon&s=25 david (Guest)
on 2005-12-04 05:36
(Received via mailing list)
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 Koontz
E34b5cae57e0dd170114dba444e37852?d=identicon&s=25 logancapaldo (Guest)
on 2005-12-05 00:17
(Received via mailing list)
On Dec 3, 2005, at 11:36 PM, David Koontz 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 Koontz
>

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]
31ab75f7ddda241830659630746cdd3a?d=identicon&s=25 halostatue (Guest)
on 2005-12-07 01:46
(Received via mailing list)
On 12/3/05, David Koontz <david@koontzfamily.org> 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
This topic is locked and can not be replied to.