2

I am getting started with C and mruby. I have a program that calls to a Ruby function using the mruby mrb_load_string function. I want to pass the argument from the C function to the Ruby function. How can I achieve this?

void on_key(const char *key) {
  mrb_load_string(mrb, "input_received()"); // how do I pass key as an argument?
}
Andrew
  • 227,796
  • 193
  • 515
  • 708

1 Answers1

2

If your ruby function takes a string as a parameter input, then:

void on_key(const char *key) {
  char arg[64];
  sprintf(arg,"input_received(\"%s\")",key);//Embed key as an argument to the function
  mrb_load_string(mrb, arg); 
}

should do what you wanted.

askmish
  • 6,464
  • 23
  • 42