Compare commits
2 Commits
7ff19b3ed5
...
72dfcb1aa1
| Author | SHA1 | Date | |
|---|---|---|---|
| 72dfcb1aa1 | |||
| 7f6e8bb273 |
2
Makefile
2
Makefile
@@ -18,7 +18,7 @@ debug: HAXE_FLAGS += -D webconsole --debug
|
|||||||
debug: build
|
debug: build
|
||||||
|
|
||||||
$(HAXE_PATH): $(shell find src -name '*.hx')
|
$(HAXE_PATH): $(shell find src -name '*.hx')
|
||||||
haxe build.hxml $(HAXE_FLAGS) --cmd "cp build/haxe.lua $(HAXE_PATH)"
|
haxe build.hxml $(HAXE_FLAGS) --cmd "mv build/_haxe.lua $(HAXE_PATH)"
|
||||||
|
|
||||||
$(MIN_PATH): $(POLYFILL_PATH)
|
$(MIN_PATH): $(POLYFILL_PATH)
|
||||||
node minify.js $(POLYFILL_PATH) $@
|
node minify.js $(POLYFILL_PATH) $@
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
--dce full
|
--dce full
|
||||||
|
|
||||||
--lua build/haxe.lua
|
|
||||||
-D lua-vanilla
|
-D lua-vanilla
|
||||||
-D lua-ver 5.1
|
-D lua-ver 5.1
|
||||||
|
|
||||||
|
--lua build/_haxe.lua
|
||||||
|
|||||||
70
src/lib/KVStore.hx
Normal file
70
src/lib/KVStore.hx
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package lib;
|
||||||
|
|
||||||
|
import haxe.Serializer;
|
||||||
|
import haxe.Unserializer;
|
||||||
|
import kernel.fs.FS;
|
||||||
|
import haxe.ds.StringMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Key value store with persistence.
|
||||||
|
**/
|
||||||
|
class KVStore {
|
||||||
|
private var kvStore: StringMap<Dynamic> = new StringMap();
|
||||||
|
private final namespace:String;
|
||||||
|
|
||||||
|
public function new(namespace: String) {
|
||||||
|
this.namespace = namespace;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function getNamespaceFile(namespace: String): String {
|
||||||
|
return '/$namespace';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function load() {
|
||||||
|
if (FS.exists(getNamespaceFile(namespace))){
|
||||||
|
var handle = FS.openRead("/" + namespace);
|
||||||
|
parseFile(handle.readAll());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save() {
|
||||||
|
var handle = FS.openWrite(getNamespaceFile(this.namespace));
|
||||||
|
|
||||||
|
handle.write(Serializer.run(this.kvStore));
|
||||||
|
|
||||||
|
handle.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parseFile(content: String) {
|
||||||
|
var unserializer = new Unserializer(content);
|
||||||
|
this.kvStore = unserializer.unserialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function set(key: String, value: Dynamic) {
|
||||||
|
this.kvStore.set(key,value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function get<T>(key: String): Null<T> {
|
||||||
|
return this.kvStore.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function exists(key: String): Bool {
|
||||||
|
return this.kvStore.exists(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function clear() {
|
||||||
|
this.kvStore.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function remove(key: String): Bool {
|
||||||
|
return this.kvStore.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function keys(): Iterator<String> {
|
||||||
|
return this.kvStore.keys();
|
||||||
|
}
|
||||||
|
|
||||||
|
public inline function keyValueIterator():KeyValueIterator<String, Dynamic> {
|
||||||
|
return this.kvStore.keyValueIterator();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user