New, callback-based architecture
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
-lib hiss
|
||||
-cp src
|
||||
-main hank.Test
|
||||
--resource C:/cygwin64/home/u0920639/hiss/src/hiss/stdlib.hiss@src/hiss/stdlib.hiss
|
||||
-main hank.Demo
|
||||
--interp
|
||||
27
src/hank/Demo.hx
Normal file
27
src/hank/Demo.hx
Normal file
@@ -0,0 +1,27 @@
|
||||
package hank;
|
||||
|
||||
import hiss.HissRepl;
|
||||
import hiss.HissReader;
|
||||
import hiss.HissTools;
|
||||
import hiss.StaticFiles;
|
||||
|
||||
class Demo implements StoryTeller {
|
||||
public static function main() {
|
||||
StaticFiles.compileWithAll("examples");
|
||||
|
||||
// TODO ask the user to choose an example
|
||||
new Story("examples/hello.hank", new Demo()).run();
|
||||
}
|
||||
|
||||
public function new() {
|
||||
|
||||
}
|
||||
|
||||
public function handleOutput(text: String) {
|
||||
trace(text);
|
||||
}
|
||||
|
||||
public function handleChoices(choices: Array<String>) {
|
||||
|
||||
}
|
||||
}
|
||||
35
src/hank/Story.hx
Normal file
35
src/hank/Story.hx
Normal file
@@ -0,0 +1,35 @@
|
||||
package hank;
|
||||
|
||||
import hiss.HTypes;
|
||||
import hiss.HissRepl;
|
||||
import hiss.StaticFiles;
|
||||
|
||||
class Story {
|
||||
var teller: StoryTeller;
|
||||
var hissRepl: HissRepl;
|
||||
var storyScript: String;
|
||||
|
||||
public function new(storyScript: String, storyTeller: StoryTeller) {
|
||||
StaticFiles.compileWith("reader-macros.hiss");
|
||||
StaticFiles.compileWith("hanklib.hiss");
|
||||
|
||||
this.storyScript = storyScript;
|
||||
teller = storyTeller;
|
||||
|
||||
|
||||
hissRepl = new HissRepl();
|
||||
|
||||
hissRepl.interp.set("*handle-output*", Function(Haxe(Fixed, function(text: HValue) {
|
||||
storyTeller.handleOutput(text.toString());
|
||||
return Nil;
|
||||
}, "*handle-output*")));
|
||||
|
||||
hissRepl.load("hanklib.hiss");
|
||||
|
||||
hissRepl.load("reader-macros.hiss");
|
||||
}
|
||||
|
||||
public function run() {
|
||||
hissRepl.load(storyScript);
|
||||
}
|
||||
}
|
||||
12
src/hank/StoryTeller.hx
Normal file
12
src/hank/StoryTeller.hx
Normal file
@@ -0,0 +1,12 @@
|
||||
package hank;
|
||||
|
||||
/**
|
||||
Due to the design of Hiss, every Hank story needs to be provided a StoryTeller to handle
|
||||
its output and choice callbacks.
|
||||
|
||||
Fortunately, this allows for some cool things, such as a StoryTestCase that implements StoryTeller.
|
||||
**/
|
||||
interface StoryTeller {
|
||||
public function handleOutput(text: String): Void;
|
||||
public function handleChoices(choices: Array<String>): Void;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package hank;
|
||||
|
||||
import hiss.HissRepl;
|
||||
import hiss.HissReader;
|
||||
import hiss.HissTools;
|
||||
|
||||
class Test {
|
||||
public static function main() {
|
||||
trace ("Running Hank examples!");
|
||||
|
||||
var exampleDir = 'src/hank/examples/';
|
||||
for (file in sys.FileSystem.readDirectory(exampleDir)) {
|
||||
var repl = new HissRepl();
|
||||
repl.load('src/hank/hank.hiss');
|
||||
|
||||
var path = haxe.io.Path.join([exampleDir, file]).toString();
|
||||
trace('Reading $file:');
|
||||
trace(HissTools.toPrint(repl.read(sys.io.File.getContent(path))));
|
||||
trace('Running $file:');
|
||||
trace(repl.load(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
5
src/hank/examples/raw.hank
Normal file
5
src/hank/examples/raw.hank
Normal file
@@ -0,0 +1,5 @@
|
||||
// Example of what a Hank file looks like AFTER being read into Hiss form!
|
||||
|
||||
(load "extra.hank")
|
||||
|
||||
(divert )
|
||||
0
src/hank/hanklib.hiss
Normal file
0
src/hank/hanklib.hiss
Normal file
@@ -13,11 +13,13 @@
|
||||
['#' => tag]];
|
||||
|
||||
[] starts choice conditional text
|
||||
{ } starts a Hiss insertion (usually for variables)
|
||||
( ) starts a Hiss funcall insertion
|
||||
{ } starts a Hiss insertion -- usually for variables
|
||||
( ) starts a Hiss funcall insertion -- equivalent to {()}
|
||||
< > starts an alt expression
|
||||
*/
|
||||
|
||||
// ( ) at the start of an output is a label
|
||||
|
||||
(setq *hank-inline-terminators* '(
|
||||
"->"
|
||||
"["
|
||||
@@ -28,4 +30,15 @@
|
||||
(defun read-output (_ stream _)
|
||||
(list 'print (get (call stream take-until (list "\n") t) output)))
|
||||
|
||||
(set-default-read-function read-output)
|
||||
(defun hank-read-mode ()
|
||||
(setq *hiss-readtable* (copy-readtable))
|
||||
; TODO set other read macros
|
||||
|
||||
|
||||
(set-default-read-function read-output))
|
||||
|
||||
(defun hiss-read-mode ()
|
||||
(set-readtable *hiss-readtable*)
|
||||
(set-default-read-function read-symbol))
|
||||
|
||||
(hank-read-mode)
|
||||
Reference in New Issue
Block a user