Jump to content

  • Log In with Google      Sign In   
  • Create Account


wdl7770016

Member Since 26 Apr 2013
Offline Last Active Apr 29 2013 05:24 AM
-----

Topics I've Started

I want to save a registered object ref type in my script class, but

29 April 2013 - 05:29 AM

the error report tell me : There is no copy operator for the type 'Entity' available.

What should I do? register a copy behaviour?but I don't find a Enum like asBEHAVE_COPY....

and mannual is no say how to do it....maybe just I not find it

help me -0 -please XD


How can I register a static const class field?

29 April 2013 - 02:59 AM

I  want to register a const unsigned int value

but the enum is only support int type

so I can't use it

finally I only could use RegisterGlobalProperty

but it can't recieve a const value

....How can I do it ?


why I can't call a script member function successfully?

27 April 2013 - 01:59 PM

I use this in my work:

 

asIScriptModule *mod = Stage::getInstance()->getScriptModule()->getBuilder()->GetModule();
    asIObjectType *type = Stage::getInstance()->getScriptModule()->getEngine()->GetObjectTypeById(mod->GetTypeIdByDecl(behaviourClassName.c_str()));
    //先判断传入的是否为脚本类的类名
    if (type == 0 ) {
        return 0;
    }
    //获取全局IBehaviour封装类
    IBehaviour *iBehaviour = Stage::getInstance()->getScriptModule()->getIBehaviour();
    //判断传入的类是否实现了IBehaviour
    if (!iBehaviour->isImplementBy(type)) {
        return 0;
    }
    //实例化传入的类类型
    string factoryDecl = behaviourClassName + " @" + behaviourClassName + "()";
    asIScriptFunction *factoryFunc = type->GetFactoryByDecl("XXXBehaviour @XXXBehaviour()");
    if (factoryFunc == 0) {
        return 0;
    }
    asIScriptContext *context = Stage::getInstance()->getScriptModule()->getAvailableContext();

    context->Prepare(factoryFunc);
    context->Execute();
    asIScriptObject *obj = *(asIScriptObject **)context->GetAddressOfReturnValue();
    if (obj == 0) {
        return 0;
    }
    //获取传入的类的类型Id(这个方法应该必定成功,因为前边已经验证了该类实现了IBehaviour接口)
    asIScriptFunction *func_getType = type->GetMethodByDecl("uint getType()");
    context->Prepare(func_getType);
    context->SetObject(obj);
    context->Execute();
    BEHAVIOUR_TYPE bType = context->GetReturnDWord();

    cout << "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" << bType << endl;
    return 0;

I register a IBehaviour interface to the engine

_engine->RegisterInterface("IBehaviour");
    _engine->RegisterInterfaceMethod("IBehaviour", "uint getType()");

I instance the XXXBehaviour and want to call it's getType method which is in IBehaviour

this is script code:

class XXXBehaviour : IBehaviour {
	XXXBehaviour() {}
	uint getType() {
		return 110;
	}
	int getInt() {
		print("kfc");
		return 120;
	}
}

but it will work only when I comment the "context->SetObject(obj);"

and through it work but the bType is still be 0, because in fact it may not work

please help me  thanks


Why I can't register a method which recieved a script class sucessfully?

26 April 2013 - 12:56 PM

this is my c++ code:

class Base {
public:
    Base() {
        _refCount = 1;
        cout << "Base Create" << endl;
    }

    void addRef() {
        _refCount++;
    }

    void release() {
        _refCount--;
        if (_refCount == 0) {
            delete this;
        }
    }

    void reciever(asIScriptObject *obj) {
        cout << "接收了" << endl;
        man = obj;
    }

    void active() {
        cout << "开始Active" << endl;
        cout << (man == 0) << endl;
        cout << "结束Active" << endl;
    }

private:
    int _refCount;
    asIScriptObject *man;
};

Base *Base_Factory() {
    return new Base();
}
......
//---------------------------------------------------------
    scriptEngine->RegisterObjectType("Base", 0, asOBJ_REF);
    scriptEngine->RegisterObjectBehaviour("Base",asBEHAVE_FACTORY, "Base@ f()", asFUNCTION(Base_Factory), asCALL_CDECL);
    scriptEngine->RegisterObjectBehaviour("Base", asBEHAVE_ADDREF, "void f()", asMETHOD(Base, addRef), asCALL_THISCALL);
    scriptEngine->RegisterObjectBehaviour("Base", asBEHAVE_RELEASE, "void f()", asMETHOD(Base, release), asCALL_THISCALL);

    //---------------------------------------------------------
    CScriptBuilder builder;
    r = builder.StartNewModule(scriptEngine, "MyModule");

    int isOK = builder.AddSectionFromFile("init.as");
    asIObjectType *type = scriptEngine->GetObjectTypeByName("Human");
    cout << "type == " << (type == 0) << endl;

    //r = builder.AddSectionFromFile("test.as");

    r = builder.BuildModule();
  
    scriptEngine->RegisterObjectMethod("Base", "void reciever(Human @in)", asMETHOD(Base, reciever), asCALL_THISCALL);
    scriptEngine->RegisterObjectMethod("Base", "void active()", asMETHOD(Base, active), asCALL_THISCALL);
........

and in my init.as script code:

class Human {
	Human(){}
}

but it is still report a error:

Failed in call to function 'RegisterObjectMethod' with 'Base' and 'void reciever(Human @in)' (code: -10)

why ?  may it must to reciever a interface nor a script class?


PARTNERS