Created
June 22, 2012 18:36
-
-
Save anonymous/2974427 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr=Array.new(3) | |
arr[0]=5 | |
arr[1]=3 | |
arr[2]=2 | |
These lines should call this function, https://github.com/ruby/ruby/blob/trunk/array.c#L568 according to this, http://www.ruby-doc.org/core-1.9.3/Array.html | |
So I have added couple of lines there to display the values of array. But i didn't get the expected result. | |
else { | |
memfill(RARRAY_PTR(ary), len, val); | |
ARY_SET_LEN(ary, len); | |
int i; | |
int result; | |
result = 0; | |
VALUE *s_arr = RARRAY_PTR(ary); | |
for(i = 0; i < len; i++) { | |
result = LONG2NUM(s_arr[i]); | |
printf("r: %d\n",result); | |
} | |
} | |
I got the result like this: | |
arr=Array.new(3) | |
arr[0]=5 | |
arr[1]=3 | |
arr[2]=2 | |
r: 9 | |
r: 9 | |
r: 9 | |
Why is this result? Why 9? | |
I have followed these to solve it: | |
How to convert ruby array to C array with RubyInline? | |
https://github.com/ruby/ruby/blob/trunk/README.EXT#L131 | |
https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L708 | |
https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L731 | |
Can anyone please help to display/printf the value of ruby array in C? | |
Any reply/answer will be highly appreciated. | |
Thanks in advanced. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment