Commit 02869e90 authored by Megax's avatar Megax
Browse files

* Frissites kesz de ugyan az a hiba mint a masiknal. Tuzedesen at kell...

* Frissites kesz de ugyan az a hiba mint a masiknal. Tuzedesen at kell vizsgalnom az okat mert lehet valahogy en okozom.
parent 19e9e632
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Lua511; using LuaWrap;
namespace LuaInterface namespace LuaInterface
{ {
...@@ -64,9 +64,9 @@ namespace LuaInterface ...@@ -64,9 +64,9 @@ namespace LuaInterface
return extractNetObject; return extractNetObject;
} }
internal ExtractValue checkType(IntPtr luaState,int stackPos,Type paramType) internal ExtractValue checkType(KopiLua.Lua.lua_State luaState,int stackPos,Type paramType)
{ {
LuaTypes luatype = LuaDLL.lua_type(luaState, stackPos); LuaTypes luatype = KopiLua.Lua.lua_type(luaState, stackPos).ToLuaTypes();
if(paramType.IsByRef) paramType=paramType.GetElementType(); if(paramType.IsByRef) paramType=paramType.GetElementType();
...@@ -84,71 +84,71 @@ namespace LuaInterface ...@@ -84,71 +84,71 @@ namespace LuaInterface
//CP: Added support for generic parameters //CP: Added support for generic parameters
if (paramType.IsGenericParameter) if (paramType.IsGenericParameter)
{ {
if (luatype == LuaTypes.LUA_TBOOLEAN) if (luatype == LuaTypes.Boolean)
return extractValues[typeof(bool).TypeHandle.Value.ToInt64()]; return extractValues[typeof(bool).TypeHandle.Value.ToInt64()];
else if (luatype == LuaTypes.LUA_TSTRING) else if (luatype == LuaTypes.String)
return extractValues[typeof(string).TypeHandle.Value.ToInt64()]; return extractValues[typeof(string).TypeHandle.Value.ToInt64()];
else if (luatype == LuaTypes.LUA_TTABLE) else if (luatype == LuaTypes.Table)
return extractValues[typeof(LuaTable).TypeHandle.Value.ToInt64()]; return extractValues[typeof(LuaTable).TypeHandle.Value.ToInt64()];
else if (luatype == LuaTypes.LUA_TUSERDATA) else if (luatype == LuaTypes.UserData)
return extractValues[typeof(object).TypeHandle.Value.ToInt64()]; return extractValues[typeof(object).TypeHandle.Value.ToInt64()];
else if (luatype == LuaTypes.LUA_TFUNCTION) else if (luatype == LuaTypes.Function)
return extractValues[typeof(LuaFunction).TypeHandle.Value.ToInt64()]; return extractValues[typeof(LuaFunction).TypeHandle.Value.ToInt64()];
else if (luatype == LuaTypes.LUA_TNUMBER) else if (luatype == LuaTypes.Number)
return extractValues[typeof(double).TypeHandle.Value.ToInt64()]; return extractValues[typeof(double).TypeHandle.Value.ToInt64()];
else else
;//an unsupported type was encountered ;//an unsupported type was encountered
} }
if (LuaDLL.lua_isnumber(luaState, stackPos)) if (KopiLua.Lua.lua_isnumber(luaState, stackPos).ToBoolean())
return extractValues[runtimeHandleValue]; return extractValues[runtimeHandleValue];
if (paramType == typeof(bool)) if (paramType == typeof(bool))
{ {
if (LuaDLL.lua_isboolean(luaState, stackPos)) if (KopiLua.Lua.lua_isboolean(luaState, stackPos))
return extractValues[runtimeHandleValue]; return extractValues[runtimeHandleValue];
} }
else if (paramType == typeof(string)) else if (paramType == typeof(string))
{ {
if (LuaDLL.lua_isstring(luaState, stackPos)) if (KopiLua.Lua.lua_isstring(luaState, stackPos).ToBoolean())
return extractValues[runtimeHandleValue]; return extractValues[runtimeHandleValue];
else if (luatype == LuaTypes.LUA_TNIL) else if (luatype == LuaTypes.Nil)
return extractNetObject; // kevinh - silently convert nil to a null string pointer return extractNetObject; // kevinh - silently convert nil to a null string pointer
} }
else if (paramType == typeof(LuaTable)) else if (paramType == typeof(LuaTable))
{ {
if (luatype == LuaTypes.LUA_TTABLE) if (luatype == LuaTypes.Table)
return extractValues[runtimeHandleValue]; return extractValues[runtimeHandleValue];
} }
else if (paramType == typeof(LuaUserData)) else if (paramType == typeof(LuaUserData))
{ {
if (luatype == LuaTypes.LUA_TUSERDATA) if (luatype == LuaTypes.UserData)
return extractValues[runtimeHandleValue]; return extractValues[runtimeHandleValue];
} }
else if (paramType == typeof(LuaFunction)) else if (paramType == typeof(LuaFunction))
{ {
if (luatype == LuaTypes.LUA_TFUNCTION) if (luatype == LuaTypes.Function)
return extractValues[runtimeHandleValue]; return extractValues[runtimeHandleValue];
} }
else if (typeof(Delegate).IsAssignableFrom(paramType) && luatype == LuaTypes.LUA_TFUNCTION) else if (typeof(Delegate).IsAssignableFrom(paramType) && luatype == LuaTypes.Function)
{ {
return new ExtractValue(new DelegateGenerator(translator, paramType).extractGenerated); return new ExtractValue(new DelegateGenerator(translator, paramType).extractGenerated);
} }
else if (paramType.IsInterface && luatype == LuaTypes.LUA_TTABLE) else if (paramType.IsInterface && luatype == LuaTypes.Table)
{ {
return new ExtractValue(new ClassGenerator(translator, paramType).extractGenerated); return new ExtractValue(new ClassGenerator(translator, paramType).extractGenerated);
} }
else if ((paramType.IsInterface || paramType.IsClass) && luatype == LuaTypes.LUA_TNIL) else if ((paramType.IsInterface || paramType.IsClass) && luatype == LuaTypes.Nil)
{ {
// kevinh - allow nil to be silently converted to null - extractNetObject will return null when the item ain't found // kevinh - allow nil to be silently converted to null - extractNetObject will return null when the item ain't found
return extractNetObject; return extractNetObject;
} }
else if (LuaDLL.lua_type(luaState, stackPos) == LuaTypes.LUA_TTABLE) else if (KopiLua.Lua.lua_type(luaState, stackPos).ToLuaTypes() == LuaTypes.Table)
{ {
if (LuaDLL.luaL_getmetafield(luaState, stackPos, "__index")) if (KopiLua.Lua.luaL_getmetafield(luaState, stackPos, "__index").ToBoolean())
{ {
object obj = translator.getNetObject(luaState, -1); object obj = translator.getNetObject(luaState, -1);
LuaDLL.lua_settop(luaState, -2); KopiLua.Lua.lua_settop(luaState, -2);
if (obj != null && paramType.IsAssignableFrom(obj.GetType())) if (obj != null && paramType.IsAssignableFrom(obj.GetType()))
return extractNetObject; return extractNetObject;
} }
...@@ -170,136 +170,142 @@ namespace LuaInterface ...@@ -170,136 +170,142 @@ namespace LuaInterface
* index stackPos as the desired type if it can, or null * index stackPos as the desired type if it can, or null
* otherwise. * otherwise.
*/ */
private object getAsSbyte(IntPtr luaState,int stackPos) private object getAsSbyte(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
sbyte retVal=(sbyte)LuaDLL.lua_tonumber(luaState,stackPos); sbyte retVal=(sbyte)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean())
return null;
return retVal; return retVal;
} }
private object getAsByte(IntPtr luaState,int stackPos) private object getAsByte(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
byte retVal=(byte)LuaDLL.lua_tonumber(luaState,stackPos); byte retVal=(byte)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean())
return null;
return retVal; return retVal;
} }
private object getAsShort(IntPtr luaState,int stackPos) private object getAsShort(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
short retVal=(short)LuaDLL.lua_tonumber(luaState,stackPos); short retVal=(short)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean())
return null;
return retVal; return retVal;
} }
private object getAsUshort(IntPtr luaState,int stackPos) private object getAsUshort(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
ushort retVal=(ushort)LuaDLL.lua_tonumber(luaState,stackPos); ushort retVal=(ushort)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsInt(IntPtr luaState,int stackPos) private object getAsInt(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
int retVal=(int)LuaDLL.lua_tonumber(luaState,stackPos); int retVal=(int)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsUint(IntPtr luaState,int stackPos) private object getAsUint(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
uint retVal=(uint)LuaDLL.lua_tonumber(luaState,stackPos); uint retVal=(uint)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsLong(IntPtr luaState,int stackPos) private object getAsLong(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
long retVal=(long)LuaDLL.lua_tonumber(luaState,stackPos); long retVal=(long)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsUlong(IntPtr luaState,int stackPos) private object getAsUlong(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
ulong retVal=(ulong)LuaDLL.lua_tonumber(luaState,stackPos); ulong retVal=(ulong)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsDouble(IntPtr luaState,int stackPos) private object getAsDouble(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
double retVal=LuaDLL.lua_tonumber(luaState,stackPos); double retVal=KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsChar(IntPtr luaState,int stackPos) private object getAsChar(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
char retVal=(char)LuaDLL.lua_tonumber(luaState,stackPos); char retVal=(char)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsFloat(IntPtr luaState,int stackPos) private object getAsFloat(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
float retVal=(float)LuaDLL.lua_tonumber(luaState,stackPos); float retVal=(float)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsDecimal(IntPtr luaState,int stackPos) private object getAsDecimal(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
decimal retVal=(decimal)LuaDLL.lua_tonumber(luaState,stackPos); decimal retVal=(decimal)KopiLua.Lua.lua_tonumber(luaState,stackPos);
if(retVal==0 && !LuaDLL.lua_isnumber(luaState,stackPos)) return null; if(retVal==0 && !KopiLua.Lua.lua_isnumber(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsBoolean(IntPtr luaState,int stackPos) private object getAsBoolean(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
return LuaDLL.lua_toboolean(luaState,stackPos); return KopiLua.Lua.lua_toboolean(luaState,stackPos);
} }
private object getAsString(IntPtr luaState,int stackPos) private object getAsString(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
string retVal=LuaDLL.lua_tostring(luaState,stackPos); string retVal=KopiLua.Lua.lua_tostring(luaState,stackPos).ToString();
if(retVal=="" && !LuaDLL.lua_isstring(luaState,stackPos)) return null; if(retVal=="" && !KopiLua.Lua.lua_isstring(luaState,stackPos).ToBoolean()) return null;
return retVal; return retVal;
} }
private object getAsTable(IntPtr luaState,int stackPos) private object getAsTable(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
return translator.getTable(luaState,stackPos); return translator.getTable(luaState,stackPos);
} }
private object getAsFunction(IntPtr luaState,int stackPos) private object getAsFunction(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
return translator.getFunction(luaState,stackPos); return translator.getFunction(luaState,stackPos);
} }
private object getAsUserdata(IntPtr luaState,int stackPos) private object getAsUserdata(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
return translator.getUserData(luaState,stackPos); return translator.getUserData(luaState,stackPos);
} }
public object getAsObject(IntPtr luaState,int stackPos) public object getAsObject(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
if(LuaDLL.lua_type(luaState,stackPos)==LuaTypes.LUA_TTABLE) if(KopiLua.Lua.lua_type(luaState,stackPos).ToLuaTypes()==LuaTypes.Table)
{ {
if(LuaDLL.luaL_getmetafield(luaState,stackPos,"__index")) if(KopiLua.Lua.luaL_getmetafield(luaState,stackPos,"__index").ToBoolean())
{ {
if(LuaDLL.luaL_checkmetatable(luaState,-1)) if(LuaLib.luaL_checkmetatable(luaState,-1))
{ {
LuaDLL.lua_insert(luaState,stackPos); KopiLua.Lua.lua_insert(luaState,stackPos);
LuaDLL.lua_remove(luaState,stackPos+1); KopiLua.Lua.lua_remove(luaState,stackPos+1);
} }
else else
{ {
LuaDLL.lua_settop(luaState,-2); KopiLua.Lua.lua_settop(luaState,-2);
} }
} }
} }
object obj=translator.getObject(luaState,stackPos); object obj=translator.getObject(luaState,stackPos);
return obj; return obj;
} }
public object getAsNetObject(IntPtr luaState,int stackPos) public object getAsNetObject(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
object obj=translator.getNetObject(luaState,stackPos); object obj=translator.getNetObject(luaState,stackPos);
if(obj==null && LuaDLL.lua_type(luaState,stackPos)==LuaTypes.LUA_TTABLE) if(obj==null && KopiLua.Lua.lua_type(luaState,stackPos).ToLuaTypes()==LuaTypes.Table)
{ {
if(LuaDLL.luaL_getmetafield(luaState,stackPos,"__index")) if(KopiLua.Lua.luaL_getmetafield(luaState,stackPos,"__index").ToBoolean())
{ {
if(LuaDLL.luaL_checkmetatable(luaState,-1)) if(LuaLib.luaL_checkmetatable(luaState,-1))
{ {
LuaDLL.lua_insert(luaState,stackPos); KopiLua.Lua.lua_insert(luaState,stackPos);
LuaDLL.lua_remove(luaState,stackPos+1); KopiLua.Lua.lua_remove(luaState,stackPos+1);
obj=translator.getNetObject(luaState,stackPos); obj=translator.getNetObject(luaState,stackPos);
} }
else else
{ {
LuaDLL.lua_settop(luaState,-2); KopiLua.Lua.lua_settop(luaState,-2);
} }
} }
} }
......
...@@ -44,7 +44,7 @@ namespace LuaInterface ...@@ -44,7 +44,7 @@ namespace LuaInterface
this.translator=translator; this.translator=translator;
this.delegateType=delegateType; this.delegateType=delegateType;
} }
public object extractGenerated(IntPtr luaState,int stackPos) public object extractGenerated(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
return CodeGeneration.Instance.GetDelegate(delegateType,translator.getFunction(luaState,stackPos)); return CodeGeneration.Instance.GetDelegate(delegateType,translator.getFunction(luaState,stackPos));
} }
...@@ -67,7 +67,7 @@ namespace LuaInterface ...@@ -67,7 +67,7 @@ namespace LuaInterface
this.translator=translator; this.translator=translator;
this.klass=klass; this.klass=klass;
} }
public object extractGenerated(IntPtr luaState,int stackPos) public object extractGenerated(KopiLua.Lua.lua_State luaState,int stackPos)
{ {
return CodeGeneration.Instance.GetClassInstance(klass,translator.getTable(luaState,stackPos)); return CodeGeneration.Instance.GetClassInstance(klass,translator.getTable(luaState,stackPos));
} }
......
This diff is collapsed.
...@@ -3,22 +3,26 @@ using System.Runtime.Serialization; ...@@ -3,22 +3,26 @@ using System.Runtime.Serialization;
namespace LuaInterface namespace LuaInterface
{ {
/// <summary> /// <summary>
/// Exceptions thrown by the Lua runtime /// Exceptions thrown by the Lua runtime
/// </summary> /// </summary>
[Serializable] [Serializable]
public class LuaException : Exception public class LuaException : Exception
{ {
public LuaException() public LuaException()
{} {
}
public LuaException(string message) : base(message) public LuaException(string message) : base(message)
{} {
}
public LuaException(string message, Exception innerException) : base(message, innerException) public LuaException(string message, Exception innerException) : base(message, innerException)
{} {
}
protected LuaException(SerializationInfo info, StreamingContext context) : base(info, context) protected LuaException(SerializationInfo info, StreamingContext context) : base(info, context)
{} {
} }
}
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Lua511; using LuaWrap;
namespace LuaInterface namespace LuaInterface
{ {
public class LuaFunction : LuaBase public class LuaFunction : LuaBase
{ {
//private Lua interpreter; //private Lua interpreter;
internal LuaCSFunction function; internal KopiLua.Lua.lua_CFunction function;
//internal int reference; //internal int reference;
public LuaFunction(int reference, Lua interpreter) public LuaFunction(int reference, Lua interpreter)
...@@ -18,7 +18,7 @@ namespace LuaInterface ...@@ -18,7 +18,7 @@ namespace LuaInterface
_Interpreter = interpreter; _Interpreter = interpreter;
} }
public LuaFunction(LuaCSFunction function, Lua interpreter) public LuaFunction(KopiLua.Lua.lua_CFunction function, Lua interpreter)
{ {
_Reference = 0; _Reference = 0;
this.function = function; this.function = function;
...@@ -77,10 +77,10 @@ namespace LuaInterface ...@@ -77,10 +77,10 @@ namespace LuaInterface
/* /*
* Pushes the function into the Lua stack * Pushes the function into the Lua stack
*/ */
internal void push(IntPtr luaState) internal void push(KopiLua.Lua.lua_State luaState)
{ {
if (_Reference != 0) if (_Reference != 0)
LuaDLL.lua_getref(luaState, _Reference); LuaLib.lua_getref(luaState, _Reference);
else else
_Interpreter.pushCSFunction(function); _Interpreter.pushCSFunction(function);
} }
......
...@@ -20,4 +20,4 @@ namespace LuaInterface ...@@ -20,4 +20,4 @@ namespace LuaInterface
/// </summary> /// </summary>
public string Description { get; set; } public string Description { get; set; }
} }
} }
\ No newline at end of file
...@@ -7,5 +7,6 @@ namespace LuaInterface ...@@ -7,5 +7,6 @@ namespace LuaInterface
/// </summary> /// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)] [AttributeUsage(AttributeTargets.Method | AttributeTargets.Field | AttributeTargets.Property)]
public sealed class LuaHideAttribute : Attribute public sealed class LuaHideAttribute : Attribute
{} {
} }
}
\ No newline at end of file
...@@ -82,7 +82,7 @@ namespace LuaWrap ...@@ -82,7 +82,7 @@ namespace LuaWrap
NoRef = -2 NoRef = -2
} }
public enum LuaType : int public enum LuaTypes : int
{ {
None = -1, None = -1,
Nil = 0, Nil = 0,
...@@ -150,9 +150,9 @@ namespace LuaWrap ...@@ -150,9 +150,9 @@ namespace LuaWrap
{ {
private static int tag = 0; private static int tag = 0;
public static LuaType ToLuaType(this int type) public static LuaTypes ToLuaTypes(this int type)
{ {
return (LuaType)type; return (LuaTypes)type;
} }
public static LuaEnum ToLuaEnum(this int lenum) public static LuaEnum ToLuaEnum(this int lenum)
...@@ -324,7 +324,7 @@ namespace LuaWrap ...@@ -324,7 +324,7 @@ namespace LuaWrap
{ {
int udata; int udata;
if(Lua.lua_type(luaState, index).ToLuaType() == LuaType.UserData) if(Lua.lua_type(luaState, index).ToLuaTypes() == LuaTypes.UserData)
{ {
if(luaL_checkmetatable(luaState, index)) if(luaL_checkmetatable(luaState, index))
{ {
......
...@@ -87,4 +87,4 @@ namespace LuaInterface ...@@ -87,4 +87,4 @@ namespace LuaInterface
} }
#endregion #endregion
} }
} }
\ No newline at end of file
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Lua511;
using System.Collections; using System.Collections;
using LuaWrap;
namespace LuaInterface namespace LuaInterface
{ {
...@@ -109,8 +109,8 @@ namespace LuaInterface ...@@ -109,8 +109,8 @@ namespace LuaInterface
{ {
object obj = _Interpreter.rawGetObject(_Reference, field); object obj = _Interpreter.rawGetObject(_Reference, field);
if (obj is LuaCSFunction) if (obj is KopiLua.Lua.lua_CFunction)
return new LuaFunction((LuaCSFunction)obj, _Interpreter); return new LuaFunction((KopiLua.Lua.lua_CFunction)obj, _Interpreter);
else else
return obj; return obj;
} }
...@@ -118,9 +118,9 @@ namespace LuaInterface ...@@ -118,9 +118,9 @@ namespace LuaInterface
/* /*
* Pushes this table into the Lua stack * Pushes this table into the Lua stack
*/ */
internal void push(IntPtr luaState) internal void push(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.lua_getref(luaState, _Reference); LuaLib.lua_getref(luaState, _Reference);
} }
public override string ToString() public override string ToString()
{ {
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Lua511; using LuaWrap;
namespace LuaInterface namespace LuaInterface
{ {
...@@ -58,9 +58,9 @@ namespace LuaInterface ...@@ -58,9 +58,9 @@ namespace LuaInterface
/* /*
* Pushes the userdata into the Lua stack * Pushes the userdata into the Lua stack
*/ */
internal void push(IntPtr luaState) internal void push(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.lua_getref(luaState, _Reference); LuaLib.lua_getref(luaState, _Reference);
} }
public override string ToString() public override string ToString()
{ {
......
This diff is collapsed.
...@@ -6,7 +6,7 @@ namespace LuaInterface ...@@ -6,7 +6,7 @@ namespace LuaInterface
using System.Reflection; using System.Reflection;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using Lua511; using LuaWrap;
/* /*
* Cached method * Cached method
...@@ -60,7 +60,7 @@ namespace LuaInterface ...@@ -60,7 +60,7 @@ namespace LuaInterface
/* /*
* Argument extraction with type-conversion function * Argument extraction with type-conversion function
*/ */
delegate object ExtractValue(IntPtr luaState, int stackPos); delegate object ExtractValue(KopiLua.Lua.lua_State luaState, int stackPos);
/* /*
* Wrapper class for methods/constructors accessed from Lua. * Wrapper class for methods/constructors accessed from Lua.
...@@ -132,14 +132,14 @@ namespace LuaInterface ...@@ -132,14 +132,14 @@ namespace LuaInterface
* Calls the method. Receives the arguments from the Lua stack * Calls the method. Receives the arguments from the Lua stack
* and returns values in it. * and returns values in it.
*/ */
public int call(IntPtr luaState) public int call(KopiLua.Lua.lua_State luaState)
{ {
MethodBase methodToCall = _Method; MethodBase methodToCall = _Method;
object targetObject = _Target; object targetObject = _Target;
bool failedCall = true; bool failedCall = true;
int nReturnValues = 0; int nReturnValues = 0;
if (!LuaDLL.lua_checkstack(luaState, 5)) if (!KopiLua.Lua.lua_checkstack(luaState, 5).ToBoolean())
throw new LuaException("Lua stack overflow"); throw new LuaException("Lua stack overflow");
bool isStatic = (_BindingType & BindingFlags.Static) == BindingFlags.Static; bool isStatic = (_BindingType & BindingFlags.Static) == BindingFlags.Static;
...@@ -153,15 +153,15 @@ namespace LuaInterface ...@@ -153,15 +153,15 @@ namespace LuaInterface
else else
targetObject = _ExtractTarget(luaState, 1); targetObject = _ExtractTarget(luaState, 1);
//LuaDLL.lua_remove(luaState,1); // Pops the receiver //KopiLua.Lua.lua_remove(luaState,1); // Pops the receiver
if (_LastCalledMethod.cachedMethod != null) // Cached? if (_LastCalledMethod.cachedMethod != null) // Cached?
{ {
int numStackToSkip = isStatic ? 0 : 1; // If this is an instance invoe we will have an extra arg on the stack for the targetObject int numStackToSkip = isStatic ? 0 : 1; // If this is an instance invoe we will have an extra arg on the stack for the targetObject
int numArgsPassed = LuaDLL.lua_gettop(luaState) - numStackToSkip; int numArgsPassed = KopiLua.Lua.lua_gettop(luaState) - numStackToSkip;
if (numArgsPassed == _LastCalledMethod.argTypes.Length) // No. of args match? if (numArgsPassed == _LastCalledMethod.argTypes.Length) // No. of args match?
{ {
if (!LuaDLL.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6)) if (!KopiLua.Lua.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6).ToBoolean())
throw new LuaException("Lua stack overflow"); throw new LuaException("Lua stack overflow");
try try
...@@ -202,7 +202,7 @@ namespace LuaInterface ...@@ -202,7 +202,7 @@ namespace LuaInterface
} }
if (_LastCalledMethod.args[_LastCalledMethod.argTypes[i].index] == null && if (_LastCalledMethod.args[_LastCalledMethod.argTypes[i].index] == null &&
!LuaDLL.lua_isnil(luaState, i + 1 + numStackToSkip)) !KopiLua.Lua.lua_isnil(luaState, i + 1 + numStackToSkip))
{ {
throw new LuaException("argument number " + (i + 1) + " is invalid"); throw new LuaException("argument number " + (i + 1) + " is invalid");
} }
...@@ -245,11 +245,11 @@ namespace LuaInterface ...@@ -245,11 +245,11 @@ namespace LuaInterface
if (targetObject == null) if (targetObject == null)
{ {
_Translator.throwError(luaState, String.Format("instance method '{0}' requires a non null target object", _MethodName)); _Translator.throwError(luaState, String.Format("instance method '{0}' requires a non null target object", _MethodName));
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
LuaDLL.lua_remove(luaState, 1); // Pops the receiver KopiLua.Lua.lua_remove(luaState, 1); // Pops the receiver
} }
bool hasMatch = false; bool hasMatch = false;
...@@ -275,7 +275,7 @@ namespace LuaInterface ...@@ -275,7 +275,7 @@ namespace LuaInterface
: ("invalid arguments to method: " + candidateName); : ("invalid arguments to method: " + candidateName);
_Translator.throwError(luaState, msg); _Translator.throwError(luaState, msg);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
} }
...@@ -302,7 +302,7 @@ namespace LuaInterface ...@@ -302,7 +302,7 @@ namespace LuaInterface
else if (methodToCall.ContainsGenericParameters) else if (methodToCall.ContainsGenericParameters)
{ {
_Translator.throwError(luaState, "unable to invoke method on generic class as the current method is an open generic method"); _Translator.throwError(luaState, "unable to invoke method on generic class as the current method is an open generic method");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
} }
...@@ -311,13 +311,13 @@ namespace LuaInterface ...@@ -311,13 +311,13 @@ namespace LuaInterface
if (!methodToCall.IsStatic && !methodToCall.IsConstructor && targetObject == null) if (!methodToCall.IsStatic && !methodToCall.IsConstructor && targetObject == null)
{ {
targetObject = _ExtractTarget(luaState, 1); targetObject = _ExtractTarget(luaState, 1);
LuaDLL.lua_remove(luaState, 1); // Pops the receiver KopiLua.Lua.lua_remove(luaState, 1); // Pops the receiver
} }
if (!_Translator.matchParameters(luaState, methodToCall, ref _LastCalledMethod)) if (!_Translator.matchParameters(luaState, methodToCall, ref _LastCalledMethod))
{ {
_Translator.throwError(luaState, "invalid arguments to method call"); _Translator.throwError(luaState, "invalid arguments to method call");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
} }
...@@ -325,7 +325,7 @@ namespace LuaInterface ...@@ -325,7 +325,7 @@ namespace LuaInterface
if (failedCall) if (failedCall)
{ {
if (!LuaDLL.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6)) if (!KopiLua.Lua.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6).ToBoolean())
throw new LuaException("Lua stack overflow"); throw new LuaException("Lua stack overflow");
try try
{ {
......
This diff is collapsed.
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