Commit 5866945e authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Un-nest LuaNativeFunction

Fixed build
Fixed iOS Build.
parent 2e501577
Subproject commit 48ed86961855816ef88d6a7486c3248e389f4317
Subproject commit 0e3dd8c9cf04ef6f7bbef7d9605c925b40789343
Subproject commit 922e92fa41c960e02023c258874ea81810884c6c
Subproject commit 4e1378477c5a6f9fc22f0a62b5fce3dd62613341
......@@ -42,11 +42,13 @@ namespace NLua
using LuaState = KopiLua.LuaState;
using LuaHook = KopiLua.LuaHook;
using LuaDebug = KopiLua.LuaDebug;
using LuaNativeFunction = KopiLua.LuaNativeFunction;
#else
using LuaCore = KeraLua.Lua;
using LuaState = KeraLua.LuaState;
using LuaHook = KeraLua.LuaHook;
using LuaDebug = KeraLua.LuaDebug;
using LuaNativeFunction = KeraLua.LuaNativeFunction;
#endif
/*
......@@ -93,7 +95,7 @@ namespace NLua
/// </summary>
public bool IsExecuting { get { return executing; } }
private LuaCore.LuaNativeFunction panicCallback;
private LuaNativeFunction panicCallback;
private ObjectTranslator translator;
/// <summary>
/// Used to ensure multiple .net threads all get serialized by this single lock for access to the lua stack/objects
......@@ -273,7 +275,7 @@ end
LuaLib.LuaLOpenLibs (luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
Init ();
// We need to keep this in a managed reference so the delegate doesn't get garbage collected
panicCallback = new LuaCore.LuaNativeFunction (PanicCallback);
panicCallback = new LuaNativeFunction (PanicCallback);
LuaLib.LuaAtPanic (luaState, panicCallback);
}
......@@ -329,7 +331,7 @@ end
}
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
static int PanicCallback (LuaState luaState)
......@@ -587,7 +589,7 @@ end
private void RegisterGlobal (string path, Type type, int recursionCounter)
{
// If the type is a global method, list it directly
if (type == typeof(LuaCore.LuaNativeFunction)) {
if (type == typeof(LuaNativeFunction)) {
// Format for easy method invocation
globals.Add (path + "(");
}
......@@ -709,7 +711,7 @@ end
public LuaFunction GetFunction (string fullPath)
{
object obj = this [fullPath];
return (obj is LuaCore.LuaNativeFunction ? new LuaFunction ((LuaCore.LuaNativeFunction)obj, this) : (LuaFunction)obj);
return (obj is LuaNativeFunction ? new LuaFunction ((LuaNativeFunction)obj, this) : (LuaFunction)obj);
}
/*
......@@ -996,7 +998,7 @@ end
/// <author>Reinhard Ostermeier</author>
///
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_Hook))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaHook))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static void DebugHookCallback (LuaState luaState, LuaDebug luaDebug)
......@@ -1136,7 +1138,7 @@ end
// We leave nothing on the stack when we are done
int oldTop = LuaLib.LuaGetTop (luaState);
var wrapper = new LuaMethodWrapper (translator, target, function.DeclaringType, function);
translator.Push (luaState, new LuaCore.LuaNativeFunction (wrapper.invokeFunction));
translator.Push (luaState, new LuaNativeFunction (wrapper.invokeFunction));
this [path] = translator.GetObject (luaState, -1);
var f = GetFunction (path);
LuaLib.LuaSetTop (luaState, oldTop);
......@@ -1156,7 +1158,7 @@ end
return (equal != 0);
}
internal void PushCSFunction (LuaCore.LuaNativeFunction function)
internal void PushCSFunction (LuaNativeFunction function)
{
translator.PushFunction (luaState, function);
}
......
......@@ -32,14 +32,16 @@ namespace NLua
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
using LuaState = KopiLua.LuaState;
using LuaNativeFunction = KopiLua.LuaNativeFunction;
#else
using LuaCore = KeraLua.Lua;
using LuaState = KeraLua.LuaState;
using LuaNativeFunction = KeraLua.LuaNativeFunction;
#endif
public class LuaFunction : LuaBase
{
internal LuaCore.LuaNativeFunction function;
internal LuaNativeFunction function;
public LuaFunction (int reference, Lua interpreter)
{
......@@ -48,7 +50,7 @@ namespace NLua
_Interpreter = interpreter;
}
public LuaFunction (LuaCore.LuaNativeFunction function, Lua interpreter)
public LuaFunction (LuaNativeFunction function, Lua interpreter)
{
_Reference = 0;
this.function = function;
......
......@@ -30,16 +30,21 @@ using NLua.Extensions;
namespace NLua
{
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
using LuaState = KopiLua.LuaState;
using LuaTag = KopiLua.LuaTag;
using LuaNativeFunction = KopiLua.LuaNativeFunction;
#else
using LuaCore = KeraLua.Lua;
using LuaState = KeraLua.LuaState;
using LuaTag = KeraLua.LuaTag;
using LuaNativeFunction = KeraLua.LuaNativeFunction;
#endif
public class LuaLib
{
public static int LuaGC (LuaState luaState, GCOptions what, int data)
......@@ -284,7 +289,7 @@ namespace NLua
LuaCore.LuaCall (luaState, nArgs, nResults);
}
public static void LuaPushStdCallCFunction (LuaState luaState, LuaCore.LuaNativeFunction function)
public static void LuaPushStdCallCFunction (LuaState luaState, LuaNativeFunction function)
{
LuaCore.LuaPushStdCallCFunction (luaState, function);
}
......@@ -294,7 +299,7 @@ namespace NLua
return LuaCore.LuaNetPCall (luaState, nArgs, nResults, errfunc);
}
public static LuaCore.LuaNativeFunction LuaToCFunction (LuaState luaState, int index)
public static LuaNativeFunction LuaToCFunction (LuaState luaState, int index)
{
return LuaCore.LuaToCFunction (luaState, index);
}
......@@ -331,9 +336,9 @@ namespace NLua
return "0"; // Because luaV_tostring does this
}
public static void LuaAtPanic (LuaState luaState, LuaCore.LuaNativeFunction panicf)
public static void LuaAtPanic (LuaState luaState, LuaNativeFunction panicf)
{
LuaCore.LuaAtPanic (luaState, (LuaCore.LuaNativeFunction)panicf);
LuaCore.LuaAtPanic (luaState, (LuaNativeFunction)panicf);
}
......
......@@ -33,9 +33,11 @@ namespace NLua
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
using LuaState = KopiLua.LuaState;
using LuaNativeFunction = KopiLua.LuaNativeFunction;
#else
using LuaCore = KeraLua.Lua;
using LuaState = KeraLua.LuaState;
using LuaNativeFunction = KeraLua.LuaNativeFunction;
#endif
/*
......@@ -102,8 +104,8 @@ namespace NLua
{
object obj = _Interpreter.RawGetObject (_Reference, field);
if (obj is LuaCore.LuaNativeFunction)
return new LuaFunction ((LuaCore.LuaNativeFunction)obj, _Interpreter);
if (obj is LuaNativeFunction)
return new LuaFunction ((LuaNativeFunction)obj, _Interpreter);
else
return obj;
}
......
......@@ -37,9 +37,11 @@ namespace NLua
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
using LuaState = KopiLua.LuaState;
using LuaNativeFunction = KopiLua.LuaNativeFunction;
#else
using LuaCore = KeraLua.Lua;
using LuaState = KeraLua.LuaState;
using LuaNativeFunction = KeraLua.LuaNativeFunction;
#endif
/*
......@@ -51,7 +53,7 @@ namespace NLua
*/
public class MetaFunctions
{
internal LuaCore.LuaNativeFunction gcFunction, indexFunction, newindexFunction, baseIndexFunction,
internal LuaNativeFunction gcFunction, indexFunction, newindexFunction, baseIndexFunction,
classIndexFunction, classNewindexFunction, execDelegateFunction, callConstructorFunction, toStringFunction;
private Dictionary<object, object> memberCache = new Dictionary<object, object> ();
private ObjectTranslator translator;
......@@ -79,22 +81,22 @@ namespace NLua
public MetaFunctions (ObjectTranslator translator)
{
this.translator = translator;
gcFunction = new LuaCore.LuaNativeFunction (MetaFunctions.CollectObject);
toStringFunction = new LuaCore.LuaNativeFunction (MetaFunctions.ToStringLua);
indexFunction = new LuaCore.LuaNativeFunction (MetaFunctions.GetMethod);
newindexFunction = new LuaCore.LuaNativeFunction (MetaFunctions.SetFieldOrProperty);
baseIndexFunction = new LuaCore.LuaNativeFunction (MetaFunctions.GetBaseMethod);
callConstructorFunction = new LuaCore.LuaNativeFunction (MetaFunctions.CallConstructor);
classIndexFunction = new LuaCore.LuaNativeFunction (MetaFunctions.GetClassMethod);
classNewindexFunction = new LuaCore.LuaNativeFunction (MetaFunctions.SetClassFieldOrProperty);
execDelegateFunction = new LuaCore.LuaNativeFunction (MetaFunctions.RunFunctionDelegate);
gcFunction = new LuaNativeFunction (MetaFunctions.CollectObject);
toStringFunction = new LuaNativeFunction (MetaFunctions.ToStringLua);
indexFunction = new LuaNativeFunction (MetaFunctions.GetMethod);
newindexFunction = new LuaNativeFunction (MetaFunctions.SetFieldOrProperty);
baseIndexFunction = new LuaNativeFunction (MetaFunctions.GetBaseMethod);
callConstructorFunction = new LuaNativeFunction (MetaFunctions.CallConstructor);
classIndexFunction = new LuaNativeFunction (MetaFunctions.GetClassMethod);
classNewindexFunction = new LuaNativeFunction (MetaFunctions.SetClassFieldOrProperty);
execDelegateFunction = new LuaNativeFunction (MetaFunctions.RunFunctionDelegate);
}
/*
* __call metafunction of CLR delegates, retrieves and calls the delegate.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int RunFunctionDelegate (LuaState luaState)
......@@ -105,7 +107,7 @@ namespace NLua
private static int RunFunctionDelegate (LuaState luaState, ObjectTranslator translator)
{
LuaCore.LuaNativeFunction func = (LuaCore.LuaNativeFunction)translator.GetRawNetObject (luaState, 1);
LuaNativeFunction func = (LuaNativeFunction)translator.GetRawNetObject (luaState, 1);
LuaLib.LuaRemove (luaState, 1);
return func (luaState);
}
......@@ -114,7 +116,7 @@ namespace NLua
* __gc metafunction of CLR objects.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int CollectObject (LuaState luaState)
......@@ -137,7 +139,7 @@ namespace NLua
* __tostring metafunction of CLR objects.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int ToStringLua (LuaState luaState)
......@@ -195,7 +197,7 @@ namespace NLua
* If the member does not exist returns nil.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetMethod (LuaState luaState)
......@@ -296,7 +298,7 @@ namespace NLua
* Adds a prefix to the method name to call the base version of the method.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetBaseMethod (LuaState luaState)
......@@ -368,8 +370,8 @@ namespace NLua
object cachedMember = CheckMemberCache (memberCache, objType, methodName);
//object cachedMember=null;
if (cachedMember is LuaCore.LuaNativeFunction) {
translator.PushFunction (luaState, (LuaCore.LuaNativeFunction)cachedMember);
if (cachedMember is LuaNativeFunction) {
translator.PushFunction (luaState, (LuaNativeFunction)cachedMember);
translator.Push (luaState, true);
return 2;
} else if (!cachedMember.IsNull ())
......@@ -447,7 +449,7 @@ namespace NLua
translator.PushType (luaState, nestedType);
} else {
// Member type must be 'method'
var wrapper = new LuaCore.LuaNativeFunction ((new LuaMethodWrapper (translator, objType, methodName, bindingType)).invokeFunction);
var wrapper = new LuaNativeFunction ((new LuaMethodWrapper (translator, objType, methodName, bindingType)).invokeFunction);
if (cachedMember.IsNull ())
SetMemberCache (memberCache, objType, methodName, wrapper);
......@@ -518,7 +520,7 @@ namespace NLua
* and error if the assignment is invalid.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int SetFieldOrProperty (LuaState luaState)
......@@ -694,7 +696,7 @@ namespace NLua
* __index metafunction of type references, works on static members.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetClassMethod (LuaState luaState)
......@@ -736,7 +738,7 @@ namespace NLua
* __newindex function of type references, works on static members.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int SetClassFieldOrProperty (LuaState luaState)
......@@ -767,7 +769,7 @@ namespace NLua
* generates an exception.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int CallConstructor (LuaState luaState)
......
......@@ -33,9 +33,11 @@ namespace NLua.Method
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
using LuaState = KopiLua.LuaState;
using LuaNativeFunction = KopiLua.LuaNativeFunction;
#else
using LuaCore = KeraLua.Lua;
using LuaState = KeraLua.LuaState;
using LuaNativeFunction = KeraLua.LuaNativeFunction;
#endif
/*
......@@ -51,7 +53,7 @@ namespace NLua.Method
*/
class LuaMethodWrapper
{
internal LuaCore.LuaNativeFunction invokeFunction;
internal LuaNativeFunction invokeFunction;
private ObjectTranslator _Translator;
private MethodBase _Method;
private MethodCache _LastCalledMethod = new MethodCache ();
......@@ -66,7 +68,7 @@ namespace NLua.Method
*/
public LuaMethodWrapper (ObjectTranslator translator, object target, IReflect targetType, MethodBase method)
{
invokeFunction = new LuaCore.LuaNativeFunction (this.Call);
invokeFunction = new LuaNativeFunction (this.Call);
_Translator = translator;
_Target = target;
......@@ -87,7 +89,7 @@ namespace NLua.Method
*/
public LuaMethodWrapper (ObjectTranslator translator, IReflect targetType, string methodName, BindingFlags bindingType)
{
invokeFunction = new LuaCore.LuaNativeFunction (this.Call);
invokeFunction = new LuaNativeFunction (this.Call);
_Translator = translator;
_MethodName = methodName;
......
......@@ -38,9 +38,11 @@ namespace NLua
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
using LuaState = KopiLua.LuaState;
using LuaNativeFunction = KopiLua.LuaNativeFunction;
#else
using LuaCore = KeraLua.Lua;
using LuaState = KeraLua.LuaState;
using LuaNativeFunction = KeraLua.LuaNativeFunction;
#endif
/*
......@@ -51,7 +53,7 @@ namespace NLua
*/
public class ObjectTranslator
{
private LuaCore.LuaNativeFunction registerTableFunction, unregisterTableFunction, getMethodSigFunction,
private LuaNativeFunction registerTableFunction, unregisterTableFunction, getMethodSigFunction,
getConstructorSigFunction, importTypeFunction, loadAssemblyFunction;
// object to object #
public readonly Dictionary<object, int> objectsBackMap = new Dictionary<object, int> ();
......@@ -86,12 +88,12 @@ namespace NLua
metaFunctions = new MetaFunctions (this);
assemblies = new List<Assembly> ();
importTypeFunction = new LuaCore.LuaNativeFunction (ObjectTranslator.ImportType);
loadAssemblyFunction = new LuaCore.LuaNativeFunction (ObjectTranslator.LoadAssembly);
registerTableFunction = new LuaCore.LuaNativeFunction (ObjectTranslator.RegisterTable);
unregisterTableFunction = new LuaCore.LuaNativeFunction (ObjectTranslator.UnregisterTable);
getMethodSigFunction = new LuaCore.LuaNativeFunction (ObjectTranslator.GetMethodSignature);
getConstructorSigFunction = new LuaCore.LuaNativeFunction (ObjectTranslator.GetConstructorSignature);
importTypeFunction = new LuaNativeFunction (ObjectTranslator.ImportType);
loadAssemblyFunction = new LuaNativeFunction (ObjectTranslator.LoadAssembly);
registerTableFunction = new LuaNativeFunction (ObjectTranslator.RegisterTable);
unregisterTableFunction = new LuaNativeFunction (ObjectTranslator.UnregisterTable);
getMethodSigFunction = new LuaNativeFunction (ObjectTranslator.GetMethodSignature);
getConstructorSigFunction = new LuaNativeFunction (ObjectTranslator.GetConstructorSignature);
CreateLuaObjectList (luaState);
CreateIndexingMetaFunction (luaState);
......@@ -251,7 +253,7 @@ namespace NLua
* if the assembly is not found.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int LoadAssembly (LuaState luaState)
......@@ -302,7 +304,7 @@ namespace NLua
* type is not found.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int ImportType (LuaState luaState)
......@@ -330,7 +332,7 @@ namespace NLua
* type passed as second argument in the stack.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int RegisterTable (LuaState luaState)
......@@ -382,7 +384,7 @@ namespace NLua
* base field, freeing the created object for garbage-collection
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int UnregisterTable (LuaState luaState)
......@@ -427,7 +429,7 @@ namespace NLua
* if no matching method is not found.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetMethodSignature (LuaState luaState)
......@@ -467,7 +469,7 @@ namespace NLua
//CP: Added ignore case
var method = klass.GetMethod (methodName, BindingFlags.Public | BindingFlags.Static |
BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase, null, signature, null);
PushFunction (luaState, new LuaCore.LuaNativeFunction ((new LuaMethodWrapper (this, target, klass, method)).invokeFunction));
PushFunction (luaState, new LuaNativeFunction ((new LuaMethodWrapper (this, target, klass, method)).invokeFunction));
} catch (Exception e) {
ThrowError (luaState, e);
LuaLib.LuaPushNil (luaState);
......@@ -481,7 +483,7 @@ namespace NLua
* if no matching constructor is found.
*/
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
[MonoTouch.MonoPInvokeCallback (typeof (LuaNativeFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
private static int GetConstructorSignature (LuaState luaState)
......@@ -508,7 +510,7 @@ namespace NLua
try {
ConstructorInfo constructor = klass.UnderlyingSystemType.GetConstructor (signature);
PushFunction (luaState, new LuaCore.LuaNativeFunction ((new LuaMethodWrapper (this, null, klass, constructor)).invokeFunction));
PushFunction (luaState, new LuaNativeFunction ((new LuaMethodWrapper (this, null, klass, constructor)).invokeFunction));
} catch (Exception e) {
ThrowError (luaState, e);
LuaLib.LuaPushNil (luaState);
......@@ -528,7 +530,7 @@ namespace NLua
/*
* Pushes a delegate into the stack
*/
internal void PushFunction (LuaState luaState, LuaCore.LuaNativeFunction func)
internal void PushFunction (LuaState luaState, LuaNativeFunction func)
{
PushObject (luaState, func, "luaNet_function");
}
......@@ -861,8 +863,8 @@ namespace NLua
(((ILuaGeneratedType)o).LuaInterfaceGetLuaTable ()).Push (luaState);
else if (o is LuaTable)
((LuaTable)o).Push (luaState);
else if (o is LuaCore.LuaNativeFunction)
PushFunction (luaState, (LuaCore.LuaNativeFunction)o);
else if (o is LuaNativeFunction)
PushFunction (luaState, (LuaNativeFunction)o);
else if (o is LuaFunction)
((LuaFunction)o).Push (luaState);
else
......
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