ID:2819846
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
I keep farting around and trying to make libraries for byond that nobody will ever use, and one of the ones I keep going back to is a delegate (function as object) wrapper. Among the many problems with this is the fact that although proc refs are a compiler type, there are no procs to validate that that is what they are.

/client/proc/test()
return "haha wheee"
/client/verb/validate_test_proc()
src << "ispath(test): [ispath(/client/proc/test)]"
src << "ispath(test,/client): [ispath(/client/proc/test,/client)]"
src << "ispath(test,/client/proc): [ispath(/client/proc/test,/client/proc)]"
src << "istype(test,/client): [ispath(/client/proc/test,/client)]"
src << "istype(test,/client/proc): [ispath(/client/proc/test,/client/proc)]"
src << "hascall(type,test): [hascall(/client,/client/proc/test)]"
src << "hascall(type,full procref as string): [hascall(/client,"/client/proc/test")]"
src << "hascall(src,test): [hascall(src,/client/proc/test)]"
src << "hascall(src,full procref as string): [hascall(src,"/client/proc/test")]"
src << "Actually calling it: [call(src,/client/proc/test)()]"

Produces:
ispath(test): 0
ispath(test,/client): 0
ispath(test,/client/proc): 0
istype(test,/client): 0
istype(test,/client/proc): 0
hascall(type,test): 0
hascall(type,full procref as string): 0
hascall(src,test): 0
hascall(src,full procref as string): 0
Actually calling it: haha wheee

I'd just like to know before I store an ambiguous untyped variable whether or not it's the correct type or going to crash later on when I actually use it.

So far I've just been kind of assuming that I would never pass anything but a proc ref to delegates, but the closer I get to actually relying on proc refs for something important, the more I realize that the complete lack of type safety is terrifying.

For my purposes, I don't care if isproc() also works like istype() or even hascall(), though hascall() working with proc refs would be nice. I know that the calling convention on the back is loose, so that you can :procname() or call("procname"). I just want to know that the type of the variable is a proc ref, so that when variables are being passed back and forth and stuck behind the couch or in weird boxes I know what I have in my hands.
A workaround for this does exist but it's so incredibly stupid I don't want to actually say it out of fear this will be closed as redundant
hascall() always works with proc names, not proc references. So you would need hascall(client,"test") for that to work.

I do see a point in having an isproc() built-in. The reason it fails ispath() is because it isn't a type path as such, as in it isn't actually an object prototype.
Well, if you see the point of a built-in one, I guess I don't have to worry about posting the stupid workaround. Courtesy of DamianQ:
#define isproc(thing) (copytext(ref(thing),4,6) == "26")