Оглавление

Любой объект

Путь: /sdk/add_on/scriptany/

Тип any является общим контейнером, который может содержать какое-либо значение. Он является типом - ссылкой.

Тип зарегестрирован с помощью RegisterScriptAny(asIScriptEngine*).

Public C++ interface

class CScriptAny
{
public:
  // Constructors
  CScriptAny(asIScriptEngine *engine);
  CScriptAny(void *ref, int refTypeId, asIScriptEngine *engine);

  // Memory management
  int AddRef();
  int Release();

  // Copy the stored value from another any object
  CScriptAny &operator=(const CScriptAny&);
  int CopyFrom(const CScriptAny *other);

  // Store the value, either as variable type, integer number, or real number
  void Store(void *ref, int refTypeId);
  void Store(asINT64 &value);
  void Store(double &value);

  // Retrieve the stored value, either as variable type, integer number, or real number
  bool Retrieve(void *ref, int refTypeId) const;
  bool Retrieve(asINT64 &value) const;
  bool Retrieve(double &value) const;

  // Get the type id of the stored value
  int GetTypeId() const;
};

Public script interface

 class any
  {
    any();
    any(? &in value);
    void store(? &in value);
    void store(int64 &in value);
    void store(double &in value);
    bool retrieve(? &out value) const;
    bool retrieve(int64 &out value) const;
    bool retrieve(double &out value) const;
  }

Использование

В скрипте можно использовать следующим образом:

int value;
obj object;
obj @handle;
any a,b,c;
a.store(value);      // store the value
b.store(@handle);    // store an object handle
c.store(object);     // store a copy of the object
a.retrieve(value);   // retrieve the value
b.retrieve(@handle); // retrieve the object handle
c.retrieve(object);  // retrieve a copy of the object

В C++:

CScriptAny *myAny;
int typeId = engine->GetTypeIdByDecl("string@");
CScriptString *str = new CScriptString("hello world");
myAny->Store((void*)&str, typeId);
myAny->Retrieve((void*)&str, typeId);

Перевод - arroy.one@gmail.com. При копировании материалов указывайте ссылку на источник.