From ba744a0e0de405e60889df5f6f4e4a091d879b80 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 20 Oct 2022 05:53:08 +0200 Subject: [PATCH] [MIRROR] Document NAMEOF and put it in a proper file [MDB IGNORE] (#17016) * Document NAMEOF and put it in a proper file (#70634) * Document NAMEOF and move it outside of varset_callback.dm * Update documentation for consistent spacing, and remove now inaccurate comment * Document NAMEOF and put it in a proper file Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- code/__HELPERS/nameof.dm | 6 ++++++ code/__HELPERS/varset_callback.dm | 3 --- tgstation.dme | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 code/__HELPERS/nameof.dm diff --git a/code/__HELPERS/nameof.dm b/code/__HELPERS/nameof.dm new file mode 100644 index 00000000000..2de37b5b8c9 --- /dev/null +++ b/code/__HELPERS/nameof.dm @@ -0,0 +1,6 @@ +/** + * NAMEOF: Compile time checked variable name to string conversion + * evaluates to a string equal to "X", but compile errors if X isn't a var on datum. + * datum may be null, but it does need to be a typed var. + **/ +#define NAMEOF(datum, X) (#X || ##datum.##X) diff --git a/code/__HELPERS/varset_callback.dm b/code/__HELPERS/varset_callback.dm index 8748af5ebe8..0c3f87328a1 100644 --- a/code/__HELPERS/varset_callback.dm +++ b/code/__HELPERS/varset_callback.dm @@ -1,6 +1,3 @@ -///datum may be null, but it does need to be a typed var -#define NAMEOF(datum, X) (#X || ##datum.##X) - #define VARSET_LIST_CALLBACK(target, var_name, var_value) CALLBACK(GLOBAL_PROC, /proc/___callbackvarset, ##target, ##var_name, ##var_value) //dupe code because dm can't handle 3 level deep macros #define VARSET_CALLBACK(datum, var, var_value) CALLBACK(GLOBAL_PROC, /proc/___callbackvarset, ##datum, NAMEOF(##datum, ##var), ##var_value) diff --git a/tgstation.dme b/tgstation.dme index 5fa50069e9d..951dcfb3642 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -403,6 +403,7 @@ #include "code\__HELPERS\memory_helpers.dm" #include "code\__HELPERS\mobs.dm" #include "code\__HELPERS\mouse_control.dm" +#include "code\__HELPERS\nameof.dm" #include "code\__HELPERS\names.dm" #include "code\__HELPERS\path.dm" #include "code\__HELPERS\piping_colors_lists.dm"