Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ruanhaishen
NLua
Commits
d0118856
Commit
d0118856
authored
Jul 10, 2013
by
Vinicius Jarina
Browse files
Fixed #29 NLua Bug after merge
parent
f0917296
Changes
4
Hide whitespace changes
Inline
Side-by-side
Core/NLua/GenerateEventAssembly/CodeGeneration.cs
View file @
d0118856
...
@@ -116,7 +116,7 @@ namespace NLua
...
@@ -116,7 +116,7 @@ namespace NLua
generator
.
Emit
(
OpCodes
.
Ldarg_0
);
generator
.
Emit
(
OpCodes
.
Ldarg_0
);
generator
.
Emit
(
OpCodes
.
Ldarg_1
);
generator
.
Emit
(
OpCodes
.
Ldarg_1
);
generator
.
Emit
(
OpCodes
.
Ldarg_2
);
generator
.
Emit
(
OpCodes
.
Ldarg_2
);
var
miGenericEventHandler
=
eventHandlerParent
.
GetMethod
(
"
h
andleEvent"
);
var
miGenericEventHandler
=
eventHandlerParent
.
GetMethod
(
"
H
andleEvent"
);
generator
.
Emit
(
OpCodes
.
Call
,
miGenericEventHandler
);
generator
.
Emit
(
OpCodes
.
Call
,
miGenericEventHandler
);
// returns
// returns
generator
.
Emit
(
OpCodes
.
Ret
);
generator
.
Emit
(
OpCodes
.
Ret
);
...
@@ -245,7 +245,7 @@ namespace NLua
...
@@ -245,7 +245,7 @@ namespace NLua
generator
.
Emit
(
OpCodes
.
Ldloc_0
);
generator
.
Emit
(
OpCodes
.
Ldloc_0
);
generator
.
Emit
(
OpCodes
.
Ldloc_1
);
generator
.
Emit
(
OpCodes
.
Ldloc_1
);
generator
.
Emit
(
OpCodes
.
Ldloc_2
);
generator
.
Emit
(
OpCodes
.
Ldloc_2
);
var
miGenericEventHandler
=
delegateParent
.
GetMethod
(
"
c
allFunction"
);
var
miGenericEventHandler
=
delegateParent
.
GetMethod
(
"
C
allFunction"
);
generator
.
Emit
(
OpCodes
.
Call
,
miGenericEventHandler
);
generator
.
Emit
(
OpCodes
.
Call
,
miGenericEventHandler
);
// Stores return value
// Stores return value
...
@@ -564,7 +564,7 @@ namespace NLua
...
@@ -564,7 +564,7 @@ namespace NLua
generator
.
Emit
(
OpCodes
.
Ldarg_0
);
generator
.
Emit
(
OpCodes
.
Ldarg_0
);
generator
.
Emit
(
OpCodes
.
Ldfld
,
luaTableField
);
generator
.
Emit
(
OpCodes
.
Ldfld
,
luaTableField
);
generator
.
Emit
(
OpCodes
.
Ldstr
,
method
.
Name
);
generator
.
Emit
(
OpCodes
.
Ldstr
,
method
.
Name
);
generator
.
Emit
(
OpCodes
.
Call
,
classHelper
.
GetMethod
(
"
g
etTableFunction"
));
generator
.
Emit
(
OpCodes
.
Call
,
classHelper
.
GetMethod
(
"
G
etTableFunction"
));
var
lab1
=
generator
.
DefineLabel
();
var
lab1
=
generator
.
DefineLabel
();
generator
.
Emit
(
OpCodes
.
Dup
);
generator
.
Emit
(
OpCodes
.
Dup
);
generator
.
Emit
(
OpCodes
.
Brtrue_S
,
lab1
);
generator
.
Emit
(
OpCodes
.
Brtrue_S
,
lab1
);
...
@@ -598,7 +598,7 @@ namespace NLua
...
@@ -598,7 +598,7 @@ namespace NLua
generator
.
Emit
(
OpCodes
.
Ldelem_Ref
);
generator
.
Emit
(
OpCodes
.
Ldelem_Ref
);
generator
.
Emit
(
OpCodes
.
Ldloc_1
);
generator
.
Emit
(
OpCodes
.
Ldloc_1
);
generator
.
Emit
(
OpCodes
.
Ldloc_2
);
generator
.
Emit
(
OpCodes
.
Ldloc_2
);
generator
.
Emit
(
OpCodes
.
Call
,
classHelper
.
GetMethod
(
"
c
allFunction"
));
generator
.
Emit
(
OpCodes
.
Call
,
classHelper
.
GetMethod
(
"
C
allFunction"
));
generator
.
MarkLabel
(
lab2
);
generator
.
MarkLabel
(
lab2
);
// Stores the function return value
// Stores the function return value
...
...
Core/NLua/Method/LuaClassHelper.cs
View file @
d0118856
...
@@ -40,6 +40,9 @@ namespace NLua.Method
...
@@ -40,6 +40,9 @@ namespace NLua.Method
*/
*/
public
static
LuaFunction
GetTableFunction
(
LuaTable
luaTable
,
string
name
)
public
static
LuaFunction
GetTableFunction
(
LuaTable
luaTable
,
string
name
)
{
{
if
(
luaTable
==
null
)
return
null
;
object
funcObj
=
luaTable
.
RawGet
(
name
);
object
funcObj
=
luaTable
.
RawGet
(
name
);
if
(
funcObj
is
LuaFunction
)
if
(
funcObj
is
LuaFunction
)
...
...
NLuaTest/AAACodeGenTests.cs
0 → 100644
View file @
d0118856
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
);
}
}
}
}
NLuaTest/NLuaTest.csproj
View file @
d0118856
...
@@ -40,9 +40,13 @@
...
@@ -40,9 +40,13 @@
<PlatformTarget>
AnyCPU
</PlatformTarget>
<PlatformTarget>
AnyCPU
</PlatformTarget>
<ErrorReport>
prompt
</ErrorReport>
<ErrorReport>
prompt
</ErrorReport>
<CodeAnalysisRuleSet>
MinimumRecommendedRules.ruleset
</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet>
MinimumRecommendedRules.ruleset
</CodeAnalysisRuleSet>
<WarningLevel>
4
</WarningLevel>
<Optimize>
false
</Optimize>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'ReleaseKopiLua|AnyCPU'"
>
<PropertyGroup
Condition=
"'$(Configuration)|$(Platform)' == 'ReleaseKopiLua|AnyCPU'"
>
<OutputPath>
..\tests\
</OutputPath>
<OutputPath>
..\tests\
</OutputPath>
<WarningLevel>
4
</WarningLevel>
<Optimize>
true
</Optimize>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"nunit.framework"
>
<Reference
Include=
"nunit.framework"
>
...
@@ -67,10 +71,11 @@
...
@@ -67,10 +71,11 @@
</Compile>
</Compile>
<Compile
Include=
"LoadFileTests.cs"
/>
<Compile
Include=
"LoadFileTests.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"AAACodeGenTests.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Core\KeraLua\src\KeraLua.csproj"
>
<ProjectReference
Include=
"..\Core\KeraLua\src\KeraLua.csproj"
>
<Project>
{47153754-10
f
5-44
d
8-
b
578-
f5a
32
b
69061
a
}
</Project>
<Project>
{47153754-10
F
5-44
D
8-
B
578-
F5A
32
B
69061
A
}
</Project>
<Name>
KeraLua
</Name>
<Name>
KeraLua
</Name>
</ProjectReference>
</ProjectReference>
<ProjectReference
Include=
"..\Core\KopiLua\KopiLua\KopiLua.csproj"
>
<ProjectReference
Include=
"..\Core\KopiLua\KopiLua\KopiLua.csproj"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment