# Dorothy 0.0.1 -- A Z-Machine interpreter library

**URL:** <https://www.ruby-forum.com/t/dorothy-0-0-1-a-z-machine-interpreter-library/151029>\
**Category:** Ruby\
**Created:** [October 16, 2008, 2:46am UTC](https://www.ruby-forum.com/t/dorothy-0-0-1-a-z-machine-interpreter-library/151029 "2008-10-16T02:46:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric\_K\_Idema](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/ea666f/32.png) [@Eric\_K\_Idema](https://www.ruby-forum.com/u/Eric_K_Idema)\
**Post date:** [October 16, 2008, 2:46am UTC](https://www.ruby-forum.com/t/dorothy-0-0-1-a-z-machine-interpreter-library/151029/1 "2008-10-16T02:46:12Z")

</div>

= Dorothy

Introducing Dorothy a Z-Machine interpreter library. The Z-Machine is  
the  
virtual machine used by many commercial and amateur works of interactive  
fiction.

Dorothy is mostly C (taken in part from Frotz) with a Ruby interface.  
The goal  
of the project is to provide the base for writing interpreters and other  
tools.

You can get the code from Github:

[http://github.com/eki/dorothy/tree/master](http://github.com/eki/dorothy/tree/master)

Currently, most of the core instructions are implemented and tested.  
But, a  
sizable number of instructions are still on the todo list. Those  
related the  
the Z-Machine’s screen model are mostly missing. As are save, restore,  
and  
restart instructions.

= Demo

It’s functioning well enough to power the demo here:

[http://ifrotz.org](http://ifrotz.org)

= RubyGems

Sorry, no gem available for this release. Go to Github to get the code.

= Sample IRB Session

eki@indus\> irb -r dorothy

> > m = Z::Machine.new( “minizork.z3” ) # Create a new machine from the given  
> > =\> #\<Z::Machine:0xb7cd7be0\> # filename

# Z::Machine#run executes instructions until the program finishes or

until

# it needs input and none is available.

> > m.run  
> > =\> nil

# The machine writes output to an array. Each token is the result of

one of

# the print instructions.

> > m.output  
> > =\> ["MINI-ZORK I: ", “The Great Underground Empire”, “\n”, "Copyright  
> > (c) 1988  
> > Infocom, Inc. All rights reserved.\nZORK is a registered trademark of  
> > Infocom,  
> > Inc.\nRelease ", 34, " / Serial number ", “8”, “7”, “1”, “1”, “2”, “4”,  
> > “\n”,  
> > “\n”, “West of House”, “\n”, "You are standing in an open field west of  
> > a white  
> > house, with a boarded front door. ", “You could circle the house to the  
> > north  
> > or south.”, “\n”, "There is a “, “small mailbox”, " here”, “.”, “\n”,  
> > “\n”,  
> > “\>”]

> > m.output.clear  
> > =\> []

# You can feed input into the machine via Z::Machine#keyboard. The

machine

# usually wants a full line of input, though sometimes it will try to

read

# individual characters. Z::Machine#run will only proceed if there’s

enough

# input available.

> > m.keyboard \<\< “open mailbox\n”  
> > =\> “open mailbox\n”  
> > m.run  
> > =\> nil

> > m.output  
> > =\> ["\> ", “open mailbox”, “\n”, "Opening the ", “small mailbox”, "  
> > reveals ",  
> > "a ", “leaflet”, “.\n”, “\n”, “\>”]
