Hi,
In message "Problems with Ruby in C"
on 02/02/18, Joakim Andersson <tyrak / borgship.net> writes:
|The Ruby program does what is expected but the C program doesn't, so I'm
|hoping that some kind soul could tell me what I'm doing wrong.
Ah, first of all, local variables does not belong to any object, so
that in the following code:
|class Context
| def execute(str)
| instance_eval(str)
| end
|end
|
|a = Context.new()
|a.execute("a = 5 ; puts a")
the assignemnt to the variable a is done in the scope of the execute
method, whic vaporized every time execute called. On the other hand,
|static VALUE cContext_execute(VALUE self, VALUE str)
|{
| return rb_funcall(self, rb_intern("instance_eval"), 1, str);
|}
this case, the assignment is done at the toplevel scope, which is used
again and again. That's the difference.
matz.