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
ae588db4
Unverified
Commit
ae588db4
authored
Sep 11, 2019
by
Vinicius Jarina
Committed by
GitHub
Sep 11, 2019
Browse files
Fixed #324 How to access index property of IDictionary<T, K> (#325)
parent
62fd5c11
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/Metatables.cs
View file @
ae588db4
...
...
@@ -484,7 +484,7 @@ namespace NLua
if
(
methodInfo
.
GetParameters
().
Length
!=
1
)
continue
;
v
ar
actualParams
=
methodInfo
.
GetParameters
();
P
ar
ameterInfo
[]
actualParams
=
methodInfo
.
GetParameters
();
if
(
actualParams
.
Length
!=
1
)
{
...
...
@@ -495,6 +495,11 @@ namespace NLua
{
// Get the index in a form acceptable to the getter
index
=
_translator
.
GetAsType
(
luaState
,
2
,
actualParams
[
0
].
ParameterType
);
// If the index type and the parameter doesn't match, just skip it
if
(
index
==
null
)
break
;
object
[]
args
=
new
object
[
1
];
// Just call the indexer - if out of bounds an exception will happen
...
...
@@ -504,6 +509,7 @@ namespace NLua
{
object
result
=
methodInfo
.
Invoke
(
obj
,
args
);
_translator
.
Push
(
luaState
,
result
);
return
1
;
}
catch
(
TargetInvocationException
e
)
{
...
...
tests/src/LuaTests.cs
View file @
ae588db4
...
...
@@ -15,6 +15,7 @@ using NUnit.Framework;
using
Lua
=
NLua
.
Lua
;
using
LuaFunction
=
NLua
.
LuaFunction
;
using
System.Diagnostics
;
using
System.Collections.Generic
;
// ReSharper disable StringLiteralTypo
...
...
@@ -2550,7 +2551,26 @@ namespace NLuaTest
}
}
[
Test
]
public
void
CallDictionary
()
{
using
(
var
lua
=
new
Lua
())
{
var
obj
=
new
Dictionary
<
string
,
string
>()
{
{
"key1"
,
"value1"
},
{
"key2"
,
"value2"
}
};
lua
[
"obj"
]
=
obj
;
lua
.
DoString
(
"i = obj.key1"
);
lua
.
DoString
(
"j = obj['key2']"
);
Assert
.
AreEqual
(
"value1"
,
lua
[
"i"
],
"#1"
);
Assert
.
AreEqual
(
"value2"
,
lua
[
"j"
],
"#2"
);
}
}
static
Lua
m_lua
;
...
...
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