Browse Source

Lua: TableTools and LuaStringTools

I made some quick externs of some of the basic lua string/table
manipulation routines.  I need to use these instead of untyped table.<x>
because lower case names like that are inferred to be instance variables
by Haxe, and instance methods get the "table:<x>" colon treatment.

This means that I need to extern pretty much all of the Lua helper
classes, but that's not such a bad thing.
Justin Donaldson 10 years ago
parent
commit
692a7ff068
2 changed files with 30 additions and 0 deletions
  1. 13 0
      std/lua/LuaStringTools.hx
  2. 17 0
      std/lua/TableTools.hx

+ 13 - 0
std/lua/LuaStringTools.hx

@@ -0,0 +1,13 @@
+package lua;
+@:native("string") 
+extern class LuaStringTools {
+	public static function len(str:String) : Int;
+	public static function sub(str:String, start:Int, end:Int) : String;
+	public static function charCodeAt(str:String, index:Int) : Int;
+	public static function find(str:String, target:String, start:Int, end :Int, plain:Bool) : Int;
+	public static function byte(str:String, index:Int) : Int;
+
+	@:overload(function(pos:Int):String{})
+	public static function substr(str:String, pos:Int, len:Int) : String;
+	//TODO: The rest
+}

+ 17 - 0
std/lua/TableTools.hx

@@ -0,0 +1,17 @@
+package lua;
+
+@:native("table") 
+extern class TableTools {
+	@:overload(function(table:Dynamic):Void{})
+	public static function concat(table:Dynamic, ?sep:String) : String;
+
+	public static function foreach(table:Dynamic, f:Dynamic->Dynamic->Void) : Void;
+	public static function foreachi(table:Dynamic, f:Dynamic->Int->Void) : Void;
+	public static function sort(table:Dynamic) : Void;
+
+	@:overload(function(table:Dynamic, value:Dynamic):Void{})
+	public static function insert(table:Dynamic, pos:Int, value:Dynamic) : Void;
+
+	@:overload(function(table:Dynamic):Void{})
+	public static function remove(table:Dynamic, ?pos:Int) : Void;
+}