ID:2829352
 
Resolved
Two new pseudo-macros, __TYPE__ and __PROC__, have been added. __TYPE__ compiles as the current type path, or as null within a global proc. __PROC__ compiles as a reference to the current proc, which will pair well with nameof().
Applies to:DM Language
Status: Resolved (515.1602)

This issue has been resolved.
Currently, Goonstation abuses the 'pile of dots' syntax to fetch a proc's type, to aid in tracking code.

Background:
We have a proc we have named `START_TRACKING`.
This roughly compiles to:
if(!by_type[PROC TYPE])
by_type[PROC TYPE] = list()
by_type[PROC TYPE][src] = 1


Now, let's look at a usage:
/obj/machinery/door/New()
..()
START_TRACKING


now, say i have
/obj/machinery/door
/obj/machinery/door/child
/obj/machinery/door/child/grandchild
/obj/machinery/door/child/grandchild/uglychild


If I use the macro and then do `by_type[/obj/machinery/door]` i will get all of them, not just the exact type match (which you'd get if you used src.type)

One could hardcode the type usage into the START_TRACKING macro, but this leads to a lot of needless verbosity. This adds up if you use this in over 500 places. It's also ripe for typos and similar unnoticed small bugs.

Implementation:
Lummox JR: I was just thinking `proc` for the current proc would be useful.

Based off this, I would say it could be: `proc::type`
Seconded. Getting the current proc would allow for variadic behavior based on the name of a verb. This is something I'd adore.
bumping this for 515
Is this what you actually want for Goonstation, or do you want
for(var/obj/machinery/door/D in world)

to be fast, so that you don't need by_type at all?
In response to Immibis
Immibis wrote:
Is this what you actually want for Goonstation, or do you want
for(var/obj/machinery/door/D in world)

to be fast, so that you don't need by_type at all?

That's not happening, so I want this feature. This feature is also useful in other contexts when you don't want to hardcode.
Lummox JR resolved issue with message:
Two new pseudo-macros, __TYPE__ and __PROC__, have been added. __TYPE__ compiles as the current type path, or as null within a global proc. __PROC__ compiles as a reference to the current proc, which will pair well with nameof().
I just figured out that you can do this by:
/node/proc/Test()
world.log << ./..
// It will output "/node/proc/Test"

There is however the limitation that you can't assign it to a variable, if you want to do so you just have to go for
/node/proc/Test()
var/L[] = new
var/idx = ..... // This will assign the proc path to the variable
L[idx] = "random"
world.log << json_encode(L)

Direct assignment as an index in the list
/node/proc/Test()
var/L[] = new
L[....] = "random" // Notice that there are 4 dots now
world.log << json_encode(L)
In response to Taitz
Taitz wrote:
I just figured out that you can do this by:

Yeah, that's what I meant by 'pile of dots' syntax.