lisdude / toaststunt

A network accessible, multi-user, programmable, interactive system for the creation of LambdaMOO style MOOs / MUDs.
63 stars 27 forks source link

toobj() #39

Closed Dino804 closed 3 years ago

Dino804 commented 3 years ago

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.

tvdijen commented 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

distantorigin commented 3 years ago

@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
lisdude commented 3 years ago

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()
Dino804 commented 3 years ago

Many thanks for the workaround. :)