Skip to content
Browse files

Breaking some things.

Added new attributes.
Reworking the translators.
Swapped LuaRuntimeException and LuaException.
  • Loading branch information...
1 parent 610bf7a commit 86290c8b12ac5077b1428c8dade4152cf36cc8b1 @JumpNotZero committed Nov 29, 2011
View
2 NLua.TestEnvironment/Program.cs
@@ -61,6 +61,8 @@ private static void Main()
double value = lua.add(3, 2);
lua.print("Adding 3 and 2 gives us " + value);
+
+ lua.SetGlobal("addmul", new Func<int, int, int, int>((first, second, multiplier) => { return (first + second) * multiplier; }));
}
Console.ReadLine();
View
58 NLua/CommonObjectTranslator.cs
@@ -25,65 +25,25 @@
#endregion
using System;
-using System.Collections.Generic;
namespace NLua
{
internal static class CommonObjectTranslator
{
- private static void PushAsUserData(IntPtr state, object value)
- {
- throw new NotImplementedException();
- }
-
public static void Push(IntPtr state, object value)
{
Type type = value.GetType();
- switch (Type.GetTypeCode(type))
+ if (type == typeof(byte) ||
+ type == typeof(sbyte) ||
+ type == typeof(ushort) ||
+ type == typeof(short) ||
+ type == typeof(uint) ||
+ type == typeof(int) ||
+ type == typeof(float) ||
+ type == typeof(double))
{
- case TypeCode.Empty:
- case TypeCode.DBNull:
- LuaCore.PushNil(state);
- break;
-
- case TypeCode.Boolean:
- LuaCore.PushBoolean(state, (bool)value);
- break;
-
- case TypeCode.Byte:
- case TypeCode.SByte:
- case TypeCode.UInt16:
- case TypeCode.Int16:
- case TypeCode.UInt32:
- case TypeCode.Int32:
- LuaCore.PushNumber(state, (double)(int)value);
- break;
-
- case TypeCode.Single:
- case TypeCode.Double:
- LuaCore.PushNumber(state, (double)value);
- break;
-
- case TypeCode.UInt64:
-
- break;
-
- case TypeCode.Int64:
-
- break;
-
- case TypeCode.Char:
- LuaCore.PushString(state, new string(new char[1] { (char)value }));
- break;
-
- case TypeCode.String:
- LuaCore.PushString(state, value as string);
- break;
-
- case TypeCode.Object:
- PushAsUserData(state, value);
- break;
+ LuaCore.PushNumber(state, (double)value);
}
}
}
View
10 NLua/Lua.cs
@@ -100,7 +100,7 @@ private IntPtr Allocate(IntPtr sender, IntPtr ptr, IntPtr originalSize, IntPtr n
private int Panic(IntPtr state)
{
- throw new LuaException(state);
+ throw new LuaRuntimeException(state);
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
@@ -141,13 +141,13 @@ public object[] CallFunction(string name, params object[] args)
if (type != LuaType.Function)
{
LuaHelper.Pop(this.state);
- throw new LuaRuntimeException("The specified global variable is not a function but is of type " + type);
+ throw new LuaException("The specified global variable is not a function but is of type " + type);
}
if (!LuaCore.CheckStack(this.state, args.Length))
{
LuaHelper.Pop(this.state);
- throw new LuaRuntimeException("There was insufficient stack space for the function's arguments.");
+ throw new LuaException("There was insufficient stack space for the function's arguments.");
}
foreach (object arg in args)
@@ -189,7 +189,7 @@ public void DoFile(string file)
if (hasErrors)
{
- throw new LuaException(this.state);
+ throw new LuaRuntimeException(this.state);
}
}
@@ -204,7 +204,7 @@ public void DoString(string chunk)
if (hasErrors)
{
- throw new LuaException(this.state);
+ throw new LuaRuntimeException(this.state);
}
}
View
6 NLua/LuaException.cs
@@ -28,14 +28,10 @@
namespace NLua
{
- public class LuaException : Exception
+ public sealed class LuaException : Exception
{
internal LuaException(string message)
: base(message)
{ }
-
- internal LuaException(IntPtr state)
- : base(LuaHelper.ToString(state, -1))
- { }
}
}
View
14 NLua/LuaExportAttribute.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace NLua
+{
+ [AttributeUsage(AttributeTargets.Method)]
+ public sealed class LuaExportAttribute : Attribute
+ {
+ public string Name
+ {
+ get;
+ set;
+ }
+ }
+}
View
14 NLua/LuaImportAttribute.cs
@@ -0,0 +1,14 @@
+using System;
+
+namespace NLua
+{
+ [AttributeUsage(AttributeTargets.Method)]
+ public sealed class LuaImportAttribute : Attribute
+ {
+ public string Name
+ {
+ get;
+ set;
+ }
+ }
+}
View
6 NLua/LuaRuntimeException.cs
@@ -28,10 +28,10 @@
namespace NLua
{
- public sealed class LuaRuntimeException : Exception
+ public class LuaRuntimeException : Exception
{
- public LuaRuntimeException(string message)
- : base(message)
+ internal LuaRuntimeException(IntPtr state)
+ : base(LuaHelper.ToString(state, -1))
{ }
}
}
View
4 NLua/NLua.csproj
@@ -59,13 +59,13 @@
<Compile Include="LuaConstant.cs" />
<Compile Include="LuaCore.cs" />
<Compile Include="LuaEventCode.cs" />
- <Compile Include="LuaException.cs" />
+ <Compile Include="LuaRuntimeException.cs" />
<Compile Include="LuaFunction.cs" />
<Compile Include="LuaGCOption.cs" />
<Compile Include="LuaHelper.cs" />
<Compile Include="LuaObjectTranslator.cs" />
<Compile Include="LuaPseudoIndex.cs" />
- <Compile Include="LuaRuntimeException.cs" />
+ <Compile Include="LuaException.cs" />
<Compile Include="LuaStandardLibraries.cs" />
<Compile Include="LuaThreadStatus.cs" />
<Compile Include="LuaType.cs" />

0 comments on commit 86290c8

Please sign in to comment.
Something went wrong with that request. Please try again.