Help us understand the problem. What is going on with this article?

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

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() みたいな関数を別途定義するなど)
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away