Welcome Guest Search | Active Topics | Log In | Register

Method called from C++ into sq class cannot access class member
#1 Posted : Thursday, May 24, 2018 9:36:31 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.
Angular brackets were replaced with lt gt because this forum sql 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]
        return _var;
//      return this._var;  [the index '_var' does not exist]

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

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");
            Sqrat::Function f1 = classobj.GetSlot( "getParam" ).Cast<Sqrat::Function>();
            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

                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
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.048 seconds.