Closed Dino804 closed 3 years ago
This has been like this since dinosaurs were on this planet... Changing this would cause a lot of backwards-compatibility issues. See Lambdamoo original builtin reference; https://tecfa.unige.ch/guides/MOO/ProgMan/ProgrammersManual_42.html#SEC42
@tvdijen is correct. This is defined functionality, not a bug. See below:
Function: obj toobj (value)
Converts the given MOO value into an object number and returns that object number. The conversions are very similar to those for toint() except that for strings, the number may be preceded by ‘#’.
toobj("34") ⇒ #34
toobj("#34") ⇒ #34
toobj("foo") ⇒ #0
toobj({1, 2}) error--> E_TYPE
If you want to work around it, though, you can always do something like:
@verb #0:bf_toobj tnt
@prog #0:bf_toobj
if (typeof(args[1]) == STR && `args[1][1] ! E_RANGE' != "#" && !$string_utils:is_numeric(args[1]))
return $nothing;
else
return toobj(@args);
endif
.
@prop $server_options.protect_toobj 1
;load_server_options()
Many thanks for the workaround. :)
I just experienced a bug in the built-in function toobj() For instance, if you evaluate ;toobj("root") (or whatever string), it returns the system object #0, but it should be returned #-1 <$nothing> instead.