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
afb6c136
Commit
afb6c136
authored
May 26, 2013
by
Vinicius Jarina
Browse files
Merge pull request #17 from Mangatome/master
Regression fix + Binary chunk DoString
parents
b6b3d0a0
647058ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Core/NLua/Lua.cs
View file @
afb6c136
...
...
@@ -440,57 +440,68 @@ end
var
result
=
translator
.
getFunction
(
luaState
,
-
1
);
translator
.
popValues
(
luaState
,
oldTop
);
return
result
;
}
/*
* Excutes a Lua chunk and returns all the chunk's return
* values in an array
*/
public
object
[]
DoString
(
string
chunk
)
{
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
if
(
LuaLib
.
luaL_loadbuffer
(
luaState
,
chunk
,
"chunk"
)
==
0
)
{
executing
=
true
;
try
{
if
(
LuaLib
.
lua_pcall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
return
translator
.
popValues
(
luaState
,
oldTop
);
else
ThrowExceptionFromError
(
oldTop
);
}
finally
{
executing
=
false
;
}
}
else
ThrowExceptionFromError
(
oldTop
);
return
null
;
// Never reached - keeps compiler happy
}
/// <summary>
/// Executes a Lua chnk and returns all the chunk's return values in an array.
/// </summary>
/// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunkName">Name to associate with the chunk</param>
/// <returns></returns>
public
object
[]
DoString
(
string
chunk
,
string
chunkName
)
{
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
executing
=
true
;
if
(
LuaLib
.
luaL_loadbuffer
(
luaState
,
chunk
,
chunkName
)
==
0
)
{
try
{
if
(
LuaLib
.
lua_pcall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
return
translator
.
popValues
(
luaState
,
oldTop
);
else
ThrowExceptionFromError
(
oldTop
);
}
finally
{
executing
=
false
;
}
}
else
ThrowExceptionFromError
(
oldTop
);
return
null
;
// Never reached - keeps compiler happy
}
/// <summary>
/// Executes a Lua chunk and returns all the chunk's return values in an array.
/// </summary>
/// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunkName">Name to associate with the chunk. Defaults to "chunk".</param>
/// <returns></returns>
public
object
[]
DoString
(
byte
[]
chunk
,
string
chunkName
=
"chunk"
)
{
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
executing
=
true
;
if
(
LuaLib
.
luaL_loadbuffer
(
luaState
,
chunk
,
chunkName
)
==
0
)
{
try
{
if
(
LuaLib
.
lua_pcall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
return
translator
.
popValues
(
luaState
,
oldTop
);
else
ThrowExceptionFromError
(
oldTop
);
}
finally
{
executing
=
false
;
}
}
else
ThrowExceptionFromError
(
oldTop
);
return
null
;
// Never reached - keeps compiler happy
}
/// <summary>
/// Executes a Lua chunk and returns all the chunk's return values in an array.
/// </summary>
/// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunkName">Name to associate with the chunk. Defaults to "chunk".</param>
/// <returns></returns>
public
object
[]
DoString
(
string
chunk
,
string
chunkName
=
"chunk"
)
{
int
oldTop
=
LuaLib
.
lua_gettop
(
luaState
);
executing
=
true
;
if
(
LuaLib
.
luaL_loadbuffer
(
luaState
,
chunk
,
chunkName
)
==
0
)
{
try
{
if
(
LuaLib
.
lua_pcall
(
luaState
,
0
,
-
1
,
0
)
==
0
)
return
translator
.
popValues
(
luaState
,
oldTop
);
else
ThrowExceptionFromError
(
oldTop
);
}
finally
{
executing
=
false
;
}
}
else
ThrowExceptionFromError
(
oldTop
);
return
null
;
// Never reached - keeps compiler happy
}
/*
...
...
Core/NLua/Metatables.cs
View file @
afb6c136
...
...
@@ -476,8 +476,21 @@ namespace NLua
*/
private
object
checkMemberCache
(
Dictionary
<
object
,
object
>
memberCache
,
IReflect
objType
,
string
memberName
)
{
var
members
=
(
Dictionary
<
object
,
object
>)
memberCache
[
objType
];
return
!
members
.
IsNull
()
?
members
[
memberName
]
:
null
;
object
members
=
null
;
if
(
memberCache
.
TryGetValue
(
objType
,
out
members
))
{
var
membersDict
=
members
as
Dictionary
<
object
,
object
>;
object
memberValue
=
null
;
if
(!
members
.
IsNull
()
&&
membersDict
.
TryGetValue
(
memberName
,
out
memberValue
))
{
return
memberValue
;
}
}
return
null
;
}
/*
...
...
@@ -485,14 +498,15 @@ namespace NLua
*/
private
void
setMemberCache
(
Dictionary
<
object
,
object
>
memberCache
,
IReflect
objType
,
string
memberName
,
object
member
)
{
var
members
=
(
Dictionary
<
object
,
object
>)
memberCache
[
objType
];
Dictionary
<
object
,
object
>
members
=
null
;
object
memberCacheValue
=
null
;
if
(
members
.
IsNull
())
{
if
(
memberCache
.
TryGetValue
(
objType
,
out
memberCacheValue
))
{
members
=
(
Dictionary
<
object
,
object
>)
memberCacheValue
;
}
else
{
members
=
new
Dictionary
<
object
,
object
>();
memberCache
[
objType
]
=
members
;
memberCache
[
objType
]
=
members
;
}
members
[
memberName
]
=
member
;
}
/*
...
...
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