ID:2293909
 
Is there any method to natively detect a var that has the static modifier at runtime?

We are working on improvements to our garbage collection queue where we automatically null all vars when sending the object to be finally Del'd (reduces deletion time), because developers keep forgetting to null them in the Destroy proc of the object as part of the soft delete functionality in ss13

This presents a problem as we never want to null static/shared class vars on an instance.

The current plan is to use a macro to prefix the var with some obvious key __static__ etc that can be checked. But just before I go ahead with that, I thought I'd check if anyone has any byond magic to test if a var is of the type static at runtime.
Nope. As a level 20 DMancer, I do not believe there is currently a method to detect static variables on a prototype.
// crude but works, somewhat
proc/get_static_vars(type)
. = list()

var/datum/instance_1 = new type
var/datum/instance_2 = new type

// wont work for anything that cant be instantiated (clients etc)
for(var/v in instance_1.vars)
try
var/original = instance_1.vars[v]
instance_1.vars[v] = 0
instance_2.vars[v] = 1

if(instance_1.vars[v] == instance_2.vars[v])
. += v

instance_1.vars[v] = original
catch

random_datum
var/static
static_var_1
static_var_2

var
non_static = 0

client/verb/test()
src << jointext(get_static_vars(/random_datum), " ,")

// output: static_var_1 ,static_var_2 ,tag