Welcome Guest Search | Active Topics | Log In | Register

calling script object method from C++ (posted again)
#1 Posted : Friday, May 25, 2018 2:05:37 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 10/10/2017(UTC)
Posts: 5
Location: Toronto

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Ass son I access a class member it crashes.

class Some extends CppClass

        base.constructor(name); //   -> calls C++ ctor OK

    function getParam(aaa) // called from C++ getParam("xxx")  OK
        return param;

    function getValue() // called from C++ getValue() AN ERROR HAS OCCURED [the index '_var' does not exist]
        print(this + "\n");   /// called from sq is an instance, called form C++ is the root table
        return _var;
//      return this._var;  [the index '_var' does not exist]

var some = Some("abc");
print(some.getValue());         //OK
print(some.getParam("xxx"));    // OK, this is a

Now from C++

CppClass* PSCR;
class CppClass
    std::string _name;
    CppClass(const char* name)_name(name)
        PSCR = this; //for the purpose of this demo
    void getValue()
        Sqrat::Object classobj = Sqrat::RootTable().GetSlot("Some"); //get's class
            Sqrat::Function f1 = classobj.GetSlot( "getParam" ).Cast<Sqrat::Function>(); // get's foo
            Sqrat::Function f2 = classobj.GetSlot( "getValue" ).Cast<Sqrat::Function>();

                Sqrat::SharedPtr<char*>   srv;
                srv = f1.Evaluate<char*>("xxx");
                std::cout << (*srv.Get()) << "\n";      //   printx xxx

               //// ???   how do I get the instance, which is 'this' actually and  getValue ends up in proper instance ???

                srv = f2.Evaluate<char*>();     // BUM!!!!
                                                //AN ERROR HAS OCCURED [the index '_var' does not exist]

            }catch(Sqrat::Exception ex){
                std::cout << ex.Message();

    static void expose(SqEnv& e){
        Sqrat::Class<SqDev> cls(e.theVM(), _SC("CppClass"));
        cls.Ctor<const char*>();
        Sqrat::RootTable().Bind(_SC("CppClass"), cls);


    /* ... */
    // run the script...

Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Clean Slate theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.4 | YAF © 2003-2010, Yet Another Forum.NET
This page was generated in 0.041 seconds.