Call methods of a script object inside C++



I couldn’t find an answer to this in the docs/tests/samples, so I came here :slight_smile: If I create an object inside a script, with some methods in it, how can I then grab a reference to that object in my host program and call these methods? I know I can use eval to grab things from a script, I can even use that for getting lambdas, but does it work with objects? Something roughly like this (half-pseudocode):


class Test
    def func(str) { return str; }

var t = Test();


auto obj = script.eval<something_here>("t");
auto result = obj.get_method_or_whatever("func")("some string);
// OR
auto method = script.eval<something_here>("t.func");
auto result = method.invoke_or_whatever("lalala");

Thanks in advance for any help!

// Get object from engine
auto obj = script.eval("t");
// Get typed std::function wrapper of method
auto func = script.eval<std::function<std::string(Boxed_Value &, const std::string &)>>("func");
// Execute function 
auto result = func(obj, "some string");
// result should be of type string and equal to the return value of `func` now



Exactly what I needed, thank you!