Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

started encoding

  • Loading branch information...
commit 36a45e768bd95e25d6e68752e1ee12e707ebe20f 1 parent f253052
@TheHippo authored
View
6 Test.hx
@@ -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
8 nYAML/NYAML.hx
@@ -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()
}
View
2  nYAML/NYAMLDecoder.hx
@@ -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
19 nYAML/NYAMLEncoder.hx
@@ -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
6 src/nyaml.cpp
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.