Skip to content

Commit f6cc429

Browse files
author
Vano
committed
SNAME macro
1 parent 30024f8 commit f6cc429

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cppscript_defs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,12 @@ static inline s_type& s_name = *reinterpret_cast<s_type*>(&s_name ## _impl);
6060
namespace impl {
6161
struct StaticAccess;
6262
};
63+
64+
/* Similar to Godot engine's SNAME macro idea or GDScript's `&"string_name"` syntax,
65+
* it creates static instance of StringName and returns reference to it.
66+
* It guarantees that `StringName` exists before calling this lambda,
67+
* but not that `StringName`s with same string literal are the same object.
68+
*/
69+
#define SNAME(str_literal) ([]() -> const ::godot::StringName& {static const ::godot::StringName str(str_literal); return str;}())
70+
6371
#endif // CPPSCRIPT_HEADER

0 commit comments

Comments
 (0)