How I can do similar for ruby. I am not able to find a example/documentation for casting a variable to object. For example
Local<Object> obj = args[0]->ToObject();
Local<Array> props = obj->GetPropertyNames();
I am re-writing a node extension in ruby. Any sort of help will be very helpful. Thanks
static Handle<Value> SendEmail(const Arguments& args)
{
HandleScope scope;
list<string> values;
Local<Object> obj = args[0]->ToObject();
Local<Array> props = obj->GetPropertyNames();
// Iterate through args[0], adding each element to our list
for(unsigned int i = 0; i < props->Length(); i++) {
String::AsciiValue val(obj->Get(i)->ToString());
values.push_front(string(*val));
}
// Display the values in the list for debugging purposes
for (list<string>::iterator it = values.begin(); it != values.end(); it++) {
cout << *it << endl;
}
return scope.Close(args.This());
}
I'm not entirely sure that I understand your question, as you flagged this question as C and your code example is C++, but either way, if you're attempting to extend ruby you'll need to convert ruby values to C types, and if you plan on using C++ data structures, from C types to C++ objects.
Using the Ruby C Api:
If you want to learn about passing structs back and forth between Ruby/C/C++, you'll need to have a thorough understanding of Ruby and the Ruby C API before you start trying to work with C++ objects.
Here are a few excellent resources to get you started:
http://silverhammermba.github.io/emberb/c/ http://java.ociweb.com/mark/NFJS/RubyCExtensions.pdf