Skip to content

Commit

Permalink
SNAME macro
Browse files Browse the repository at this point in the history
  • Loading branch information
Vano committed Mar 7, 2024
1 parent 30024f8 commit f6cc429
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cppscript_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,12 @@ static inline s_type& s_name = *reinterpret_cast<s_type*>(&s_name ## _impl);
namespace impl {
struct StaticAccess;
};

/* Similar to Godot engine's SNAME macro idea or GDScript's `&"string_name"` syntax,
* it creates static instance of StringName and returns reference to it.
* It guarantees that `StringName` exists before calling this lambda,
* but not that `StringName`s with same string literal are the same object.
*/
#define SNAME(str_literal) ([]() -> const ::godot::StringName& {static const ::godot::StringName str(str_literal); return str;}())

#endif // CPPSCRIPT_HEADER

0 comments on commit f6cc429

Please sign in to comment.