0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AngelScript で C++ から std::string を AS に渡す

0
Posted at

AngelScript 便利ですね!

スクリプト言語AngelScriptの紹介
https://qiita.com/unknown_ds/items/8d64aaafd8e5ccd9ab14

Angel Script をアプリケーションに組み込もう
https://qiita.com/Ushio/items/cc5f9aa1abeb56f0d6f1

文字列を AS スクリプトに渡したい

文字列(scriptstring)を AS スクリプトに引数で渡したいと思いました(C/C++ での argv のように).

ドキュメントには string を渡す方法は記述がありませんが, SetArgObjectstd::string のアドレスを渡すといけました.

以下がコード例です.

scriptstring の add_on を忘れずに登録しておいてください.

// AngelScript
void myfunc(const string arg)
{
  Print(arg); // `Print` は別途定義した関数(Tutorial あたりを参照ください) 
}
...
auto func = module->GetFunctionByDecl("void myfunc(const string arg)");
std::string muda = "muda";

auto ctx = engine->CreateContext();
ctx->Prepare(func);

ctx->SetArgObject(&muda);

ctx->Execute();

また, リファレンス(?)渡し(const string &in) はダメでした.

TODO

  • クラスを作って渡したほうが安全かも?
  • C++ から直接呼ぶ関数の引数としては string を渡さないほうがいいかも?(getstring() みたいな関数を別途定義するなど)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?