New LValueFromValue() to convert from any Javascript value (almost) to a LValue

Sun, 23 May 2010 02:29:04 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 23 May 2010 02:29:04 +0100
changeset 27
35a2203253a6
parent 26
5c7eafb47830
child 28
d14b47c3870f

New LValueFromValue() to convert from any Javascript value (almost) to a LValue

lvm.js file | annotate | diff | comparison | revisions
--- a/lvm.js	Sat May 22 20:14:33 2010 +0100
+++ b/lvm.js	Sun May 23 02:29:04 2010 +0100
@@ -60,6 +60,25 @@
 	return new LValue("function", func);
 }
 
+function LValueFromValue(value)
+{
+	switch(typeof(value))
+	{
+	case "string":
+		return new LValueFromString(value);
+	case "function":
+		return new LValueFromFunction(value);
+	case "object":
+		if(value == null)
+			return new LValue("nil", value);
+	default:
+		sys.puts( "Not able to convert type " +
+			typeof(value)+" from Javascript to Lua: "+sys.inspect(value));
+		throw "Not able to convert type " +
+			typeof(value)+" from Javascript to Lua";
+	}
+}
+
 function LBinaryChunk(chunk, start)
 {
 	this.chunk = chunk;

mercurial