YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

calling script object method from C++ (posted again)
comarius
#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)
Hi,
Ass son I access a class member it crashes.
Code:

class Some extends CppClass
{
    _var=null;

    constructor(name)
    {
        base.constructor(name); //   -> calls C++ ctor OK
        _var=7;
    }

    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++
Code:

CppClass* PSCR;
class CppClass
{
    std::string _name;
public:
    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
        if(!classobj.IsNull())
        {
            Sqrat::Function f1 = classobj.GetSlot( "getParam" ).Cast<Sqrat::Function>(); // get's foo
            Sqrat::Function f2 = classobj.GetSlot( "getValue" ).Cast<Sqrat::Function>();

         
            try{
                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);
    }

};

main()
{
    /* ... */
    CppClass::expose(VM);
    // run the script...
    PSCR->getValue();
   
}




mariusco
#2 Posted : Monday, July 16, 2018 5:04:56 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/11/2018(UTC)
Posts: 5
Location: toronto

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
solved, see previous post
elinarobin
#3 Posted : Monday, July 30, 2018 7:55:28 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/30/2018(UTC)
Posts: 1
Location: New york

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Actually, C++ is a very popular object-oriented programming language. But users may get trouble in case of calling the script method using this language. You surely get the solution from gmail support to resolve such kind of problem.
Users browsing this topic
Guest
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.111 seconds.