loading...

Discussion on: Storing C data in an MRuby class

Collapse
mdorier profile image
Matthieu Dorier

Thanks for your answer! I also asked the question as an issue on the mruby repo and got an answer about using the C macros. My code works, now.

My use-case for allocating an object in a function that isn't a constructor was not to allocate more memory for "self", but to allocate a new object. Imagine the following code:

class Foo
...
end

class Bar
...
def do_something
...
return Foo.new
end
end

Now imagine Foo and Bar are actually not defined in Ruby but in C, and do_something is a C function, you would need to create an instance of Foo from inside a C function.