Оглавление

Словарь

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

Словарь хранит имена и соответсвующие им значения объектов.

Регистрируется с помошью RegisterScriptDictionary(asIScriptEngine*).

Public C++ interface

class CScriptDictionary
{
public:
  // Управление памятью
  CScriptDictionary(asIScriptEngine *engine);
  void AddRef();
  void Release();

  // Ставит/Получает значение для ключа
  void Set(const std::string &key, void *value, int typeId);
  bool Get(const std::string &key, void *value, int typeId) const;

  // Ставит/Получает номер(integer) для ключа
  void Set(const std::string &key, asINT64 &value);
  bool Get(const std::string &key, asINT64 &value) const;

  // Ставит/Получает номер (real) для ключа
  void Set(const std::string &key, double &value);
  bool Get(const std::string &key, double &value) const;

  // Возвращает true если ключ установлен
  bool Exists(const std::string &key) const;
  
  // Удаляет ключ
  void Delete(const std::string &key);
  
  // Удаляет все ключи
  void DeleteAll();
};

Public script interface

class dictionary
{
  void set(const string &in key, ? &in value);
  bool get(const string &in value, ? &out value) const;
  void set(const string &in key, int64 &in value);
  bool get(const string &in key, int64 &out value) const;
  void set(const string &in key, double &in value);
  bool get(const string &in key, double &out value) const;
  bool exists(const string &in key) const;
  void delete(const string &in key);
  void deleteAll();
}

Пример скрипта

dictionary dict;
obj object;
obj @handle;
dict.set("one", 1);
dict.set("object", object);
dict.set("handle", @handle);
if( dict.exists("one") )
{
  bool found = dict.get("handle", @handle);
  if( found )
  {
    dict.delete("object");
  }
}
dict.deleteAll();

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