Stunt Builtins

12 views
Skip to first unread message

Stephen Gigante

unread,
May 14, 2012, 9:06:25 AM5/14/12
to moo-talk
I've noticed stunt has added a bunch of new builtins.  Some of these (parents, chparents) have been added to the programmer's manual, but others (respond_to is the only one I know of) have no documentation at all. (Not that hard to work out with a bunch of evaling and the examples in the kernel package, but still, docs would be nice)
And because I can't be bothered diving through the source right now, I was wondering if there was a full list of new builtins added in Stunt, and descriptions of what they do.

 - Stephen

Todd Sundsted

unread,
May 14, 2012, 10:46:50 AM5/14/12
to MOO Talk
Oh boy, looks like i need to finish writing the docs!

It's no replacement for real documentation, but the readme lists
"most" of the new builtins. Various posts in this group probably
capture the rest... like I said, it's no replacement :-)

Todd

michael munson

unread,
May 14, 2012, 3:35:43 PM5/14/12
to MOO-...@googlegroups.com
Heres some I know of:

isa(obj,obj)
switch_player(obj,obj)
generate_json(ANY)
parse_json(STR)
read_http(str,obj)
exec(list);
all the normal FileIO builtins
string_hash(str,[str]);
binary_hash(str,[str]);
value_hash(any,[str]);
string_hmac(str,str);
binary_hmac(str,str);
encode_base64(str)
decode_base64(str)
mapdelete(map,any)
mapkeys(map)
mapvalues(map)

may not be a complete list

--
You received this message because you are subscribed to the Google Groups "MOO Talk" group.
To post to this group, send email to MOO-...@googlegroups.com.
To unsubscribe from this group, send email to MOO-talk+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/MOO-talk?hl=en.


Todd Sundsted

unread,
May 15, 2012, 6:38:23 AM5/15/12
to MOO Talk
Nice list, Michael! My two cents follows:

> switch_player(<obj1>, <obj2>)

Wiz-only. Silently switches the player associated with this
connection from obj1 to obj2. obj1 must be connected and obj2 must be
a user/player. I use this in do_login_command() verbs that read or
suspend (which prevents the normal player selection mechanism from
working.

> exec({<cmd>, <arg>...}, <in>) => {<code>, <out>, <err>}

Wiz-only. Asynchronously executes the program pointed to by filename
<cmd>, passing the arguments <args>, and sending the string <in> on
stdin. The current task is suspended until the program exits. When
the program exits the task is resumed, the call to `exec()' returns
with the return code of the process in <code>, and anything written to
stdout or stderr in <out> and <err> respectively. <in>, <out> and
<err> are all binary strings. The program to be executed must be in
the directory "executables/" inside of the directory in which the
server is running.

> generate_json(<json>, [<opts>])
> parse_json(<str>, [<opts>])

Generate/parse a JSON string. <opts> specifies how primitive values
are handled. "common-subset" maps floats/ints to JSON numbers and
everything else to strings. "embedded-types" embeds MOO type
information in the JSON strings. For example, E_FLOAT becomes
"E_FLOAT|err"; likewise, "E_FLOAT|err" is parsed as E_FLOAT. The type
is the three (or four) letter abbreviation for the MOO type: err, str,
obj, etc.

> encode_base64(<str>)
> decode_base64(<str>)

Base64 encode/decode <str>. <str> is a binary string.

> isa(<obj1>, <obj2>)

Returns true if <obj1> is a descendant of <obj2>, otherwise false.

> respond_to(<obj>, <verb>)

Returns true if <verb> is callable on <obj>, taking into account
inheritance, wildcards (star verbs), etc. otherwise false. If the
caller is permitted to read the object (because the object's `r' flag
is true, or the caller is the owner or a wizard) the true value is a
list containing the object number of the object that defines the verb
and the full verb name(s). Otherwise, the numeric value `1' is
returned.

> string_hash(<str>, [<str>])
> binary_hash(<str>, [<str>])
> value_hash(<any>, [<str>])

Extends the existing built-ins to take an optional second argument
specifying the hash algorithm. Currently supports "sha256" (the
default), "sha1" and "md5". MD5 exists for backwards compatibility
but _should not be used as a cryptographic hash_ anymore (other uses
are okay).

> string_hmac(<str>, <key>)
> binary_hmac(<str>, <key>)
> value_hmac(<any>, <key>)

Computes a SHA256 HMAC from the value and the given key. <key> is a
binary string.

> mapkeys(<map>)
> mapvalues(<map>)

Returns the given map's keys or values, respectively.

> mapdelete(<map>, <key>)

Deletes the key/value pair from the map, given the pair's <key>.
Returns the updated map.



Hopefully I haven't missed anything.

Todd


On May 14, 3:35 pm, michael munson <michael.d.mun...@gmail.com> wrote:
> Heres some I know of:
>
> isa(obj,obj)
> switch_player(obj,obj)
> generate_json(ANY)
> parse_json(STR)
> read_http(str,obj)
> exec(list);
> all the normal FileIO builtins
> string_hash(str,[str]);
> binary_hash(str,[str]);
> value_hash(any,[str]);
> string_hmac(str,str);
> binary_hmac(str,str);
> encode_base64(str)
> decode_base64(str)
> mapdelete(map,any)
> mapkeys(map)
> mapvalues(map)
>
> may not be a complete list
>

michael munson

unread,
May 16, 2012, 11:37:07 AM5/16/12
to Todd Sundsted, MOO Talk
On an unrelated note I wonder if an explode() bf would provide much speed benefit vs MOO implementation of explode found in $string_utils or $str_proto

Todd Sundsted

unread,
May 16, 2012, 7:28:57 PM5/16/12
to MOO Talk
Forgot one... no, two:

> set_task_local(<any>)
> task_local() => any

Wiz-perm builtins that set/get a value associated with the current
task. Persistent across suspend/dump/load, etc. Automatically freed
when the task completes. Great for securely stashing intermediate
values.

Todd

Todd Sundsted

unread,
May 16, 2012, 7:32:37 PM5/16/12
to MOO Talk
I'd be surprised if it didn't. Explode, in particular, is hard to do
well in MOOcode with the built-ins available, IMHO.

Todd

On May 16, 11:37 am, michael munson <michael.d.mun...@gmail.com>
wrote:
> On an unrelated note I wonder if an explode() bf would provide much speed
> benefit vs MOO implementation of explode found in $string_utils or
> $str_proto
>

Tim van Dijen

unread,
May 16, 2012, 8:56:26 PM5/16/12
to MOO-...@googlegroups.com
I have a seemingly good version of explode() here.. Using it for years
already @ PhantasyWorld
You can find it on sourceforge;
http://sourceforge.net/tracker/?func=detail&aid=2059203&group_id=3692&atid=303692

There's some $set_utils builtins there as well, that save huge amounts
of ticks!

It is also possible to have ANSI be parsed by the server... I use a
parse_ansi() and remove_ansi() builtin to do so.. If implemented well,
any add-ons and exemptions to the default ANSI can be added to
$ansi_utils:notify.. I am willing to post that code as well..

Goblin
Reply all
Reply to author
Forward
0 new messages