Commit d0118856 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fixed #29 NLua Bug after merge

parent f0917296
......@@ -116,7 +116,7 @@ namespace NLua
generator.Emit (OpCodes.Ldarg_0);
generator.Emit (OpCodes.Ldarg_1);
generator.Emit (OpCodes.Ldarg_2);
var miGenericEventHandler = eventHandlerParent.GetMethod ("handleEvent");
var miGenericEventHandler = eventHandlerParent.GetMethod ("HandleEvent");
generator.Emit (OpCodes.Call, miGenericEventHandler);
// returns
generator.Emit (OpCodes.Ret);
......@@ -245,7 +245,7 @@ namespace NLua
generator.Emit (OpCodes.Ldloc_0);
generator.Emit (OpCodes.Ldloc_1);
generator.Emit (OpCodes.Ldloc_2);
var miGenericEventHandler = delegateParent.GetMethod ("callFunction");
var miGenericEventHandler = delegateParent.GetMethod ("CallFunction");
generator.Emit (OpCodes.Call, miGenericEventHandler);
// Stores return value
......@@ -564,7 +564,7 @@ namespace NLua
generator.Emit (OpCodes.Ldarg_0);
generator.Emit (OpCodes.Ldfld, luaTableField);
generator.Emit (OpCodes.Ldstr, method.Name);
generator.Emit (OpCodes.Call, classHelper.GetMethod ("getTableFunction"));
generator.Emit (OpCodes.Call, classHelper.GetMethod ("GetTableFunction"));
var lab1 = generator.DefineLabel ();
generator.Emit (OpCodes.Dup);
generator.Emit (OpCodes.Brtrue_S, lab1);
......@@ -598,7 +598,7 @@ namespace NLua
generator.Emit (OpCodes.Ldelem_Ref);
generator.Emit (OpCodes.Ldloc_1);
generator.Emit (OpCodes.Ldloc_2);
generator.Emit (OpCodes.Call, classHelper.GetMethod ("callFunction"));
generator.Emit (OpCodes.Call, classHelper.GetMethod ("CallFunction"));
generator.MarkLabel (lab2);
// Stores the function return value
......
......@@ -40,6 +40,9 @@ namespace NLua.Method
*/
public static LuaFunction GetTableFunction (LuaTable luaTable, string name)
{
if (luaTable == null)
return null;
object funcObj = luaTable.RawGet (name);
if (funcObj is LuaFunction)
......
using System;
using System.Text;
using System.Collections.Generic;
using NUnit.Framework;
using NLuaTest.Mock;
using System.Reflection;
using System.Threading;
using NLua;
using NLua.Exceptions;
namespace NLuaTest
{
[TestFixture]
public class AAACodeGenTests
{
/*
* Tests passing a Lua function to a delegate
* with value-type arguments
*/
[Test]
public void LuaDelegateValueTypes ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return x+y; end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate1(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
}
/*
* Tests passing a Lua function to a delegate
* with value-type arguments and out params
*/
[Test]
public void LuaDelegateValueTypesOutParam ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x) return x,x*2; end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate2(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (6, a);
//Console.WriteLine("delegate returned: "+a);
}
}
/*
* Tests passing a Lua function to a delegate
* with value-type arguments and ref params
*/
[Test]
public void LuaDelegateValueTypesByRefParam ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return x+y; end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate3(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
}
/*
* Tests passing a Lua function to a delegate
* with value-type arguments that returns a reference type
*/
[Test]
public void LuaDelegateValueTypesReturnReferenceType ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return TestClass(x+y); end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate4(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
}
/*
* Tests passing a Lua function to a delegate
* with reference type arguments
*/
[Test]
public void LuaDelegateReferenceTypes ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return x.testval+y.testval; end");
lua.DoString ("a=test:callDelegate5(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
}
/*
* Tests passing a Lua function to a delegate
* with reference type arguments and an out param
*/
[Test]
public void LuaDelegateReferenceTypesOutParam ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x) return x,TestClass(x*2); end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callDelegate6(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (6, a);
//Console.WriteLine("delegate returned: "+a);
}
}
/*
* Tests passing a Lua function to a delegate
* with reference type arguments and a ref param
*/
[Test]
public void LuaDelegateReferenceTypesByRefParam ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("function func(x,y) return TestClass(x+y.testval); end");
lua.DoString ("a=test:callDelegate7(func)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("delegate returned: "+a);
}
}
/*
* Tests passing a Lua table as an interface and
* calling one of its methods with value-type params
*/
[Test]
public void NLuaAAValueTypes ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test=TestClass()");
lua.DoString ("itest={}");
lua.DoString ("function itest:test1(x,y) return x+y; end");
lua.DoString ("test=TestClass()");
lua.DoString ("a=test:callInterface1(itest)");
int a = (int)lua.GetNumber ("a");
Assert.AreEqual (5, a);
//Console.WriteLine("interface returned: "+a);
}
}
/*
* Tests making an object from a Lua table and calling the base
* class version of one of the methods the table overrides.
*/
[Test]
public void LuaTableBaseMethod ()
{
using (Lua lua = new Lua ()) {
lua.DoString ("luanet.load_assembly('NLuaTest')");
lua.DoString ("TestClass=luanet.import_type('NLuaTest.Mock.TestClass')");
lua.DoString ("test={}");
lua.DoString ("function test:overridableMethod(x,y) print(self[base]); return 6 end");
lua.DoString ("luanet.make_object(test,'NLuaTest.Mock.TestClass')");
lua.DoString ("a=TestClass.callOverridable(test,2,3)");
int a = (int)lua.GetNumber ("a");
lua.DoString ("luanet.free_object(test)");
Assert.AreEqual (6, a);
}
}
}
}
......@@ -40,9 +40,13 @@
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseKopiLua|AnyCPU'">
<OutputPath>..\tests\</OutputPath>
<WarningLevel>4</WarningLevel>
<Optimize>true</Optimize>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework">
......@@ -67,10 +71,11 @@
</Compile>
<Compile Include="LoadFileTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="AAACodeGenTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\KeraLua\src\KeraLua.csproj">
<Project>{47153754-10f5-44d8-b578-f5a32b69061a}</Project>
<Project>{47153754-10F5-44D8-B578-F5A32B69061A}</Project>
<Name>KeraLua</Name>
</ProjectReference>
<ProjectReference Include="..\Core\KopiLua\KopiLua\KopiLua.csproj">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment