Created
June 19, 2011 12:00
-
-
Save kimoto/1034189 to your computer and use it in GitHub Desktop.
SourcePawn Idioms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SourcePawn慣用句集 | |
| //=============================== | |
| // 日常用例集 | |
| //=============================== | |
| *文字列の結合 | |
| buffer変数に追記する形の例 | |
| ------------------------ | |
| new String:buffer[256]; | |
| StrCat(buffer, 256, "aaa"); | |
| StrCat(buffer, 256, "bbb"); | |
| StrCat(buffer, 256, "ccc"); | |
| ------------------------ | |
| *文字列バッファの動的確保 | |
| new String:変数名[バッファサイズ]; でいける | |
| ------------------------ | |
| new a = 3; | |
| new String:buffer[a]; | |
| buffer[0] = 'A'; | |
| buffer[0] = 'A'; | |
| buffer[0] = 'A'; | |
| ------------------------ | |
| *二つの文字を結合、バッファは動的に確保 | |
| strlenでstr1とstr2の文字サイズ測ってバッファ確保 | |
| StrCatで連結して格納 | |
| ------------------------ | |
| // str1 + str2 + '\0'(1 byte) | |
| new total_size = strlen(str1) + strlen(str2) + 1; | |
| new String:concat[total_size]; | |
| StrCat(concat, total_size, str1); | |
| StrCat(concat, total_size, str2); | |
| ------------------------ | |
| //=============================== | |
| // その他 | |
| //=============================== | |
| *可変引数関数の作り方 | |
| ...で可変関数であることを定義できる | |
| 可変な引数の文字列組み立てするのがVFormat関数で、VFormatの第四引数に何番目の引数から可変なのかを指定 | |
| この例だと仮引数の2番目が...なので2を指定している | |
| ------------------------ | |
| #define DEBUG_STRING_BUFFER_SIZE 5120 | |
| public DebugPrint(const String:Message[], any:...) | |
| { | |
| if (true) | |
| { | |
| decl String:DebugBuff[DEBUG_STRING_BUFFER_SIZE]; | |
| VFormat(DebugBuff, sizeof(DebugBuff), Message, 2); | |
| LogMessage(DebugBuff); | |
| } | |
| } | |
| ------------------------ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment