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
d8ae863a
Commit
d8ae863a
authored
Oct 17, 2019
by
Vinicius Jarina
Browse files
Fixed conversion of Lua String -> .NET `byte []` + test
parent
321aeb27
Changes
2
Show whitespace changes
Inline
Side-by-side
src/CheckType.cs
View file @
d8ae863a
...
...
@@ -32,6 +32,7 @@ namespace NLua
_extractValues
.
Add
(
typeof
(
bool
),
GetAsBoolean
);
_extractValues
.
Add
(
typeof
(
string
),
GetAsString
);
_extractValues
.
Add
(
typeof
(
char
[]),
GetAsCharArray
);
_extractValues
.
Add
(
typeof
(
byte
[]),
GetAsByteArray
);
_extractValues
.
Add
(
typeof
(
LuaFunction
),
GetAsFunction
);
_extractValues
.
Add
(
typeof
(
LuaTable
),
GetAsTable
);
_extractValues
.
Add
(
typeof
(
LuaUserData
),
GetAsUserdata
);
...
...
@@ -113,7 +114,7 @@ namespace NLua
if
(
luatype
==
LuaType
.
Number
)
return
_extractValues
[
typeof
(
double
)];
}
bool
netParamIsString
=
paramType
==
typeof
(
string
)
||
paramType
==
typeof
(
char
[]);
bool
netParamIsString
=
paramType
==
typeof
(
string
)
||
paramType
==
typeof
(
char
[])
||
paramType
==
typeof
(
byte
[])
;
if
(
netParamIsNumeric
)
{
...
...
@@ -329,6 +330,15 @@ namespace NLua
return
retVal
.
ToCharArray
();
}
private
object
GetAsByteArray
(
LuaState
luaState
,
int
stackPos
)
{
if
(!
luaState
.
IsString
(
stackPos
))
return
null
;
byte
[]
retVal
=
luaState
.
ToBuffer
(
stackPos
,
false
);
return
retVal
;
}
private
object
GetAsString
(
LuaState
luaState
,
int
stackPos
)
{
if
(!
luaState
.
IsString
(
stackPos
))
...
...
tests/src/LuaTests.cs
View file @
d8ae863a
...
...
@@ -16,7 +16,7 @@ using Lua = NLua.Lua;
using
LuaFunction
=
NLua
.
LuaFunction
;
using
System.Diagnostics
;
using
System.Collections.Generic
;
using
System.
Collections
;
using
System.
Linq
;
// ReSharper disable StringLiteralTypo
...
...
@@ -2600,6 +2600,25 @@ namespace NLuaTest
}
}
[
Test
]
public
void
ByteArrayParameter
()
{
using
(
var
lua
=
new
Lua
())
{
lua
[
"WriteBinary"
]
=
(
Action
<
byte
[
]>
)
WriteBinary
;
lua
.
DoString
(
@"
local value = string.char(1, 2, 3, 0x3f, 0x40, 0xff, 0xf3, 0x9f)
WriteBinary (value);
"
);
}
}
private
void
WriteBinary
(
byte
[]
buffer
)
{
byte
[]
expected
=
{
1
,
2
,
3
,
0x3f
,
0x40
,
0xff
,
0xf3
,
0x9f
};
Assert
.
True
(
Enumerable
.
SequenceEqual
(
expected
,
buffer
));
}
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