Commit 296814ea authored by Mangatome's avatar Mangatome
Browse files

DoString binary chunks and simplifications

- Simplified DoString for strings by replacing DoString(string,string)
and DoString(string) by a single method DoString(string[,string]).
- Added DoString(byte[][,string]) to allow for usage of binary chunks.
parent 4cfc1f2b
...@@ -442,53 +442,64 @@ end ...@@ -442,53 +442,64 @@ end
return result; return result;
} }
/* /// <summary>
* Excutes a Lua chunk and returns all the chunk's return /// Executes a Lua chunk and returns all the chunk's return values in an array.
* values in an array /// </summary>
*/ /// <param name = "chunk">Chunk to execute</param>
public object[] DoString (string chunk) /// <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); int oldTop = LuaLib.lua_gettop(luaState);
if (LuaLib.luaL_loadbuffer (luaState, chunk, "chunk") == 0) {
executing = true; executing = true;
try { if (LuaLib.luaL_loadbuffer(luaState, chunk, chunkName) == 0)
if (LuaLib.lua_pcall (luaState, 0, -1, 0) == 0) {
return translator.popValues (luaState, oldTop); try
{
if (LuaLib.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop);
else else
ThrowExceptionFromError (oldTop); ThrowExceptionFromError(oldTop);
} finally { }
finally
{
executing = false; executing = false;
} }
} else }
ThrowExceptionFromError (oldTop); else
ThrowExceptionFromError(oldTop);
return null; // Never reached - keeps compiler happy return null; // Never reached - keeps compiler happy
} }
/// <summary> /// <summary>
/// Executes a Lua chnk and returns all the chunk's return values in an array. /// Executes a Lua chunk and returns all the chunk's return values in an array.
/// </summary> /// </summary>
/// <param name = "chunk">Chunk to execute</param> /// <param name = "chunk">Chunk to execute</param>
/// <param name = "chunkName">Name to associate with the chunk</param> /// <param name = "chunkName">Name to associate with the chunk. Defaults to "chunk".</param>
/// <returns></returns> /// <returns></returns>
public object[] DoString (string chunk, string chunkName) public object[] DoString(string chunk, string chunkName = "chunk")
{ {
int oldTop = LuaLib.lua_gettop (luaState); int oldTop = LuaLib.lua_gettop(luaState);
executing = true; executing = true;
if (LuaLib.luaL_loadbuffer (luaState, chunk, chunkName) == 0) { if (LuaLib.luaL_loadbuffer(luaState, chunk, chunkName) == 0)
try { {
if (LuaLib.lua_pcall (luaState, 0, -1, 0) == 0) try
return translator.popValues (luaState, oldTop); {
if (LuaLib.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop);
else else
ThrowExceptionFromError (oldTop); ThrowExceptionFromError(oldTop);
} finally { }
finally
{
executing = false; executing = false;
} }
} else }
ThrowExceptionFromError (oldTop); else
ThrowExceptionFromError(oldTop);
return null; // Never reached - keeps compiler happy return null; // Never reached - keeps compiler happy
} }
......
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