Permalink
Browse files

started encoding

  • Loading branch information...
1 parent f253052 commit 36a45e768bd95e25d6e68752e1ee12e707ebe20f @TheHippo committed May 19, 2010
Showing with 32 additions and 9 deletions.
  1. +4 −2 Test.hx
  2. +3 −5 nYAML/NYAML.hx
  3. +1 −1 nYAML/NYAMLDecoder.hx
  4. +19 −0 nYAML/NYAMLEncoder.hx
  5. +5 −1 src/nyaml.cpp
View
@@ -1,7 +1,9 @@
class Test {
static function main() {
var file = neko.io.File.read("test.yaml",true);
- for (doc in nYAML.NYAML.decode(file.readAll().toString()))
- trace(Std.string(doc)+": "+Type.typeof(doc));
+ var docs = nYAML.NYAML.decode(file.readAll().toString());
+ for (doc in docs)
+ trace(Std.string(doc));
+ trace(nYAML.NYAML.encode(docs));
}
}
View
@@ -2,12 +2,10 @@ package nYAML;
class NYAML {
- public static function encode(o:Dynamic):String {
- throw "not implemented yet!";
- return "";
- }
+ public inline static function encode(o:Array<Dynamic>):String
+ return new nYAML.NYAMLEncoder(o).getOutput()
- public static function decode(s:String):Array<Dynamic>
+ public inline static function decode(s:String):Array<Dynamic>
return new nYAML.NYAMLDecoder(s).getData()
}
@@ -2,7 +2,7 @@ package nYAML;
class NYAMLDecoder {
- static var decode:String->Void = neko.Lib.load("nyaml","decode",1);
+ static var decode = neko.Lib.load("nyaml","decode",1);
var data:Dynamic;
View
@@ -0,0 +1,19 @@
+package nYAML;
+
+class NYAMLEncoder {
+
+ static var encode = neko.Lib.load("nyaml","encode",1);
+
+ var out:String;
+
+ public function new(data:Array<Dynamic>) {
+ var ret = new List<String>();
+ for (x in data)
+ ret.push(neko.Lib.nekoToHaxe(NYAMLEncoder.encode(neko.Lib.haxeToNeko(x))));
+ out = ret.join("\n---\n");
+ }
+
+ public inline function getOutput()
+ return out
+
+}
View
@@ -112,6 +112,10 @@ value decode(value str) {
return ret;
}
+value encode(value ar) {
+ return alloc_string("foo");
+}
-DEFINE_PRIM(decode,1);
+DEFINE_PRIM(decode,1);
+DEFINE_PRIM(encode,1);

0 comments on commit 36a45e7

Please sign in to comment.