* Registers an object's method as a Lua function (global or table field)
* The method may have any signature
*/
publicLuaFunctionRegisterFunction(stringpath,objecttarget,MethodBasefunction/*MethodInfo function*/)//CP: Fix for struct constructor by Alexander Kappner (link: http://luaforge.net/forum/forum.php?thread_id=2859&forum_id=145)
/// Base class to provide consistent disposal flow across lua objects. Uses code provided by Yves Duhoux and suggestions by Hans Schmeidenbacher and Qingrui Li
lua.RegisterFunction(method.Name,null,method);// CLR name
else
lua.RegisterFunction(attribute.Name,null,method);// Custom name
}
}
}
#endregion
#regionEnumeration
/// <summary>
/// Registers an enumeration's values for usage as a Lua variable table
/// </summary>
/// <typeparam name="T">The enum type to register</typeparam>
/// <param name="lua">The Lua VM to add the enum to</param>
[SuppressMessage("Microsoft.Design","CA1004:GenericMethodsShouldProvideTypeParameter",Justification="The type parameter is used to select an enum type")]
Debug.WriteLine(string.Format("An error occurred during an attempt to retrieve an extractor ({0}) while checking for params array status.",paramElementType.FullName));
* Passes errors (argument e) to the Lua interpreter
*/
internalvoidthrowError(IntPtrluaState,objecte)
internalvoidthrowError(IntPtrluaState,objecte)
{
// If the argument is a mere string, we are free to add extra info to it (as opposed to some private C# exception object or somesuch, which we just pass up)
if(eisstring)
{
// We use this to remove anything pushed by luaL_where
intoldTop=LuaDLL.lua_gettop(luaState);
intoldTop=LuaLib.lua_gettop(luaState);
// Stack frame #1 is our C# wrapper, so not very interesting to the user
// Stack frame #2 must be the lua code that called us, so that's what we want to use
LuaDLL.luaL_where(luaState,1);
LuaLib.luaL_where(luaState,2);
object[]curlev=popValues(luaState,oldTop);
// Debug.WriteLine(curlev);
// Determine the position in the script where the exception was triggered
stringerrLocation="";
if(curlev.Length>0)
errLocation=curlev[0].ToString();
stringmessage=easstring;
if(message!=null)
{
// Wrap Lua error (just a string) and store the error location
e=newLuaScriptException(message,errLocation);
}
else
{
Exceptionex=easException;
if(ex!=null)
{
// Wrap generic .NET exception as an InnerException and store the error location
e=newLuaScriptException(ex,errLocation);
}
e=curlev[0].ToString()+e;
}
push(luaState,e);
LuaDLL.lua_error(luaState);
push(luaState,e);
LuaLib.lua_error(luaState);
}
/*
* Implementation of load_assembly. Throws an error
// Note: starting with lua5.1 the garbage collector may remove weak reference items (such as our luaNet_objects values) when the initial GC sweep
// occurs, but the actual call of the __gc finalizer for that object may not happen until a little while later. During that window we might call
// this routine and find the element missing from luaNet_objects, but collectObject() has not yet been called. In that case, we go ahead and call collect
// object here
// did we find a non nil object in our table? if not, we need to call collect object
LuaTypestype=LuaDLL.lua_type(luaState,-1);
if(type!=LuaTypes.LUA_TNIL)
LuaTypetype=LuaLib.lua_type(luaState,-1);
if(type!=LuaType.Nil)
{
LuaDLL.lua_remove(luaState,-2);// drop the metatable - we're going to leave our object on the stack
LuaLib.lua_remove(luaState,-2);// drop the metatable - we're going to leave our object on the stack
return;
}
// MetaFunctions.dumpStack(this, luaState);
LuaDLL.lua_remove(luaState,-1);// remove the nil object value
LuaDLL.lua_remove(luaState,-1);// remove the metatable
LuaLib.lua_remove(luaState,-1);// remove the nil object value
LuaLib.lua_remove(luaState,-1);// remove the metatable
collectObject(o,index);// Remove from both our tables and fall out to get a new ID
}
...
...
@@ -475,48 +454,48 @@ namespace LuaInterface
if(metatable=="luaNet_metatable")
{
// Gets or creates the metatable for the object's type