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));
} }
......
...@@ -8,7 +8,7 @@ namespace LuaInterface ...@@ -8,7 +8,7 @@ namespace LuaInterface
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Reflection; using System.Reflection;
using System.Threading; using System.Threading;
using Lua511; using LuaWrap;
/* /*
* Main class of LuaInterface * Main class of LuaInterface
...@@ -24,7 +24,6 @@ namespace LuaInterface ...@@ -24,7 +24,6 @@ namespace LuaInterface
[CLSCompliant(true)] [CLSCompliant(true)]
public class Lua : IDisposable public class Lua : IDisposable
{ {
static string init_luanet = static string init_luanet =
"local metatable = {} \n"+ "local metatable = {} \n"+
"local import_type = luanet.import_type \n"+ "local import_type = luanet.import_type \n"+
...@@ -65,10 +64,10 @@ namespace LuaInterface ...@@ -65,10 +64,10 @@ namespace LuaInterface
"-- Preload the mscorlib assembly \n"+ "-- Preload the mscorlib assembly \n"+
"luanet.load_assembly(\"mscorlib\") \n"; "luanet.load_assembly(\"mscorlib\") \n";
/*readonly */ IntPtr luaState; /*readonly */ KopiLua.Lua.lua_State luaState;
ObjectTranslator translator; ObjectTranslator translator;
LuaCSFunction panicCallback, lockCallback, unlockCallback; KopiLua.Lua.lua_CFunction panicCallback/*, lockCallback, unlockCallback*/;
/// <summary> /// <summary>
/// Used to ensure multiple .net threads all get serialized by this single lock for access to the lua stack/objects /// Used to ensure multiple .net threads all get serialized by this single lock for access to the lua stack/objects
...@@ -77,30 +76,30 @@ namespace LuaInterface ...@@ -77,30 +76,30 @@ namespace LuaInterface
public Lua() public Lua()
{ {
luaState = LuaDLL.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone) luaState = KopiLua.Lua.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone)
//LuaDLL.luaopen_base(luaState); // steffenj: luaopen_* no longer used //KopiLua.Lua.luaopen_base(luaState); // steffenj: luaopen_* no longer used
LuaDLL.luaL_openlibs(luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here) KopiLua.Lua.luaL_openlibs(luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
LuaDLL.lua_pushstring(luaState, "LUAINTERFACE LOADED"); KopiLua.Lua.lua_pushstring(luaState, "LUAINTERFACE LOADED");
LuaDLL.lua_pushboolean(luaState, true); KopiLua.Lua.lua_pushboolean(luaState, 1);
LuaDLL.lua_settable(luaState, (int) LuaIndexes.LUA_REGISTRYINDEX); KopiLua.Lua.lua_settable(luaState, (int)PseudoIndex.Registry);
LuaDLL.lua_newtable(luaState); KopiLua.Lua.lua_newtable(luaState);
LuaDLL.lua_setglobal(luaState, "luanet"); KopiLua.Lua.lua_setglobal(luaState, "luanet");
LuaDLL.lua_pushvalue(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); KopiLua.Lua.lua_pushvalue(luaState, (int)PseudoIndex.Globals);
LuaDLL.lua_getglobal(luaState, "luanet"); KopiLua.Lua.lua_getglobal(luaState, "luanet");
LuaDLL.lua_pushstring(luaState, "getmetatable"); KopiLua.Lua.lua_pushstring(luaState, "getmetatable");
LuaDLL.lua_getglobal(luaState, "getmetatable"); KopiLua.Lua.lua_getglobal(luaState, "getmetatable");
LuaDLL.lua_settable(luaState, -3); KopiLua.Lua.lua_settable(luaState, -3);
LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); KopiLua.Lua.lua_replace(luaState, (int)PseudoIndex.Globals);
translator=new ObjectTranslator(this,luaState); translator=new ObjectTranslator(this,luaState);
LuaDLL.lua_replace(luaState, (int)LuaIndexes.LUA_GLOBALSINDEX); KopiLua.Lua.lua_replace(luaState, (int)PseudoIndex.Globals);
LuaDLL.luaL_dostring(luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring LuaLib.luaL_dostring(luaState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring
// We need to keep this in a managed reference so the delegate doesn't get garbage collected // We need to keep this in a managed reference so the delegate doesn't get garbage collected
panicCallback = new LuaCSFunction(PanicCallback); panicCallback = new KopiLua.Lua.lua_CFunction(PanicCallback);
LuaDLL.lua_atpanic(luaState, panicCallback); KopiLua.Lua.lua_atpanic(luaState, panicCallback);
//LuaDLL.lua_atlock(luaState, lockCallback = new LuaCSFunction(LockCallback)); //KopiLua.Lua.lua_atlock(luaState, lockCallback = new KopiLua.Lua.lua_CFunction(LockCallback));
//LuaDLL.lua_atunlock(luaState, unlockCallback = new LuaCSFunction(UnlockCallback)); //KopiLua.Lua.lua_atunlock(luaState, unlockCallback = new KopiLua.Lua.lua_CFunction(UnlockCallback));
} }
private bool _StatePassed; private bool _StatePassed;
...@@ -108,33 +107,33 @@ namespace LuaInterface ...@@ -108,33 +107,33 @@ namespace LuaInterface
/* /*
* CAUTION: LuaInterface.Lua instances can't share the same lua state! * CAUTION: LuaInterface.Lua instances can't share the same lua state!
*/ */
public Lua(Int64 luaState) public Lua(KopiLua.Lua.lua_State luaState)
{ {
IntPtr lState = new IntPtr(luaState); KopiLua.Lua.lua_State lState = luaState;
LuaDLL.lua_pushstring(lState, "LUAINTERFACE LOADED"); KopiLua.Lua.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaDLL.lua_gettable(lState, (int)LuaIndexes.LUA_REGISTRYINDEX); KopiLua.Lua.lua_gettable(lState, (int)PseudoIndex.Registry);
if(LuaDLL.lua_toboolean(lState,-1)) if(KopiLua.Lua.lua_toboolean(lState,-1).ToBoolean())
{ {
LuaDLL.lua_settop(lState,-2); KopiLua.Lua.lua_settop(lState,-2);
throw new LuaException("There is already a LuaInterface.Lua instance associated with this Lua state"); throw new LuaException("There is already a LuaInterface.Lua instance associated with this Lua state");
} }
else else
{ {
LuaDLL.lua_settop(lState,-2); KopiLua.Lua.lua_settop(lState,-2);
LuaDLL.lua_pushstring(lState, "LUAINTERFACE LOADED"); KopiLua.Lua.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaDLL.lua_pushboolean(lState, true); KopiLua.Lua.lua_pushboolean(lState, 1);
LuaDLL.lua_settable(lState, (int)LuaIndexes.LUA_REGISTRYINDEX); KopiLua.Lua.lua_settable(lState, (int)PseudoIndex.Registry);
this.luaState=lState; this.luaState=lState;
LuaDLL.lua_pushvalue(lState, (int)LuaIndexes.LUA_GLOBALSINDEX); KopiLua.Lua.lua_pushvalue(lState, (int)PseudoIndex.Globals);
LuaDLL.lua_getglobal(lState, "luanet"); KopiLua.Lua.lua_getglobal(lState, "luanet");
LuaDLL.lua_pushstring(lState, "getmetatable"); KopiLua.Lua.lua_pushstring(lState, "getmetatable");
LuaDLL.lua_getglobal(lState, "getmetatable"); KopiLua.Lua.lua_getglobal(lState, "getmetatable");
LuaDLL.lua_settable(lState, -3); KopiLua.Lua.lua_settable(lState, -3);
LuaDLL.lua_replace(lState, (int)LuaIndexes.LUA_GLOBALSINDEX); KopiLua.Lua.lua_replace(lState, (int)PseudoIndex.Globals);
translator=new ObjectTranslator(this, this.luaState); translator=new ObjectTranslator(this, this.luaState);
LuaDLL.lua_replace(lState, (int)LuaIndexes.LUA_GLOBALSINDEX); KopiLua.Lua.lua_replace(lState, (int)PseudoIndex.Globals);
LuaDLL.luaL_dostring(lState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring LuaLib.luaL_dostring(lState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring
} }
_StatePassed = true; _StatePassed = true;
...@@ -145,7 +144,7 @@ namespace LuaInterface ...@@ -145,7 +144,7 @@ namespace LuaInterface
/// </summary> /// </summary>
/// <param name="luaState"></param> /// <param name="luaState"></param>
/// Not yet used /// Not yet used
int LockCallback(IntPtr luaState) int LockCallback(KopiLua.Lua.lua_State luaState)
{ {
// Monitor.Enter(luaLock); // Monitor.Enter(luaLock);
...@@ -157,7 +156,7 @@ namespace LuaInterface ...@@ -157,7 +156,7 @@ namespace LuaInterface
/// </summary> /// </summary>
/// <param name="luaState"></param> /// <param name="luaState"></param>
/// Not yet used /// Not yet used
int UnlockCallback(IntPtr luaState) int UnlockCallback(KopiLua.Lua.lua_State luaState)
{ {
// Monitor.Exit(luaLock); // Monitor.Exit(luaLock);
...@@ -169,15 +168,16 @@ namespace LuaInterface ...@@ -169,15 +168,16 @@ namespace LuaInterface
if (_StatePassed) if (_StatePassed)
return; return;
if (luaState != IntPtr.Zero) ////// if (luaState != KopiLua.Lua.lua_State.Zero)
LuaDLL.lua_close(luaState); if (luaState != null)
//luaState = IntPtr.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id=44593&forum_id=146 KopiLua.Lua.lua_close(luaState);
//luaState = KopiLua.Lua.lua_State.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id=44593&forum_id=146
} }
static int PanicCallback(IntPtr luaState) static int PanicCallback(KopiLua.Lua.lua_State luaState)
{ {
// string desc = LuaDLL.lua_tostring(luaState, 1); // string desc = KopiLua.Lua.lua_tostring(luaState, 1);
string reason = String.Format("unprotected error in call to Lua API ({0})", LuaDLL.lua_tostring(luaState, -1)); string reason = String.Format("unprotected error in call to Lua API ({0})", KopiLua.Lua.lua_tostring(luaState, -1));
// lua_tostring(L, -1); // lua_tostring(L, -1);
...@@ -193,7 +193,7 @@ namespace LuaInterface ...@@ -193,7 +193,7 @@ namespace LuaInterface
void ThrowExceptionFromError(int oldTop) void ThrowExceptionFromError(int oldTop)
{ {
object err = translator.getObject(luaState, -1); object err = translator.getObject(luaState, -1);
LuaDLL.lua_settop(luaState, oldTop); KopiLua.Lua.lua_settop(luaState, oldTop);
// A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved) // A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved)
LuaScriptException luaEx = err as LuaScriptException; LuaScriptException luaEx = err as LuaScriptException;
...@@ -218,7 +218,7 @@ namespace LuaInterface ...@@ -218,7 +218,7 @@ namespace LuaInterface
if (caughtExcept != null) if (caughtExcept != null)
{ {
translator.throwError(luaState, caughtExcept); translator.throwError(luaState, caughtExcept);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
...@@ -241,12 +241,12 @@ namespace LuaInterface ...@@ -241,12 +241,12 @@ namespace LuaInterface
/// <returns></returns> /// <returns></returns>
public LuaFunction LoadString(string chunk, string name) public LuaFunction LoadString(string chunk, string name)
{ {
int oldTop = LuaDLL.lua_gettop(luaState); int oldTop = KopiLua.Lua.lua_gettop(luaState);
executing = true; executing = true;
try try
{ {
if (LuaDLL.luaL_loadbuffer(luaState, chunk, name) != 0) if (LuaLib.luaL_loadbuffer(luaState, chunk, name) != 0)
ThrowExceptionFromError(oldTop); ThrowExceptionFromError(oldTop);
} }
finally { executing = false; } finally { executing = false; }
...@@ -264,8 +264,8 @@ namespace LuaInterface ...@@ -264,8 +264,8 @@ namespace LuaInterface
/// <returns></returns> /// <returns></returns>
public LuaFunction LoadFile(string fileName) public LuaFunction LoadFile(string fileName)
{ {
int oldTop = LuaDLL.lua_gettop(luaState); int oldTop = KopiLua.Lua.lua_gettop(luaState);
if (LuaDLL.luaL_loadfile(luaState, fileName) != 0) if (KopiLua.Lua.luaL_loadfile(luaState, fileName) != 0)
ThrowExceptionFromError(oldTop); ThrowExceptionFromError(oldTop);
LuaFunction result = translator.getFunction(luaState, -1); LuaFunction result = translator.getFunction(luaState, -1);
...@@ -281,13 +281,13 @@ namespace LuaInterface ...@@ -281,13 +281,13 @@ namespace LuaInterface
*/ */
public object[] DoString(string chunk) public object[] DoString(string chunk)
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
if (LuaDLL.luaL_loadbuffer(luaState, chunk, "chunk") == 0) if (LuaLib.luaL_loadbuffer(luaState, chunk, "chunk") == 0)
{ {
executing = true; executing = true;
try try
{ {
if (LuaDLL.lua_pcall(luaState, 0, -1, 0) == 0) if (KopiLua.Lua.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop); return translator.popValues(luaState, oldTop);
else else
ThrowExceptionFromError(oldTop); ThrowExceptionFromError(oldTop);
...@@ -308,13 +308,13 @@ namespace LuaInterface ...@@ -308,13 +308,13 @@ namespace LuaInterface
/// <returns></returns> /// <returns></returns>
public object[] DoString(string chunk, string chunkName) public object[] DoString(string chunk, string chunkName)
{ {
int oldTop = LuaDLL.lua_gettop(luaState); int oldTop = KopiLua.Lua.lua_gettop(luaState);
executing = true; executing = true;
if (LuaDLL.luaL_loadbuffer(luaState, chunk, chunkName) == 0) if (LuaLib.luaL_loadbuffer(luaState, chunk, chunkName) == 0)
{ {
try try
{ {
if (LuaDLL.lua_pcall(luaState, 0, -1, 0) == 0) if (KopiLua.Lua.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop); return translator.popValues(luaState, oldTop);
else else
ThrowExceptionFromError(oldTop); ThrowExceptionFromError(oldTop);
...@@ -333,13 +333,13 @@ namespace LuaInterface ...@@ -333,13 +333,13 @@ namespace LuaInterface
*/ */
public object[] DoFile(string fileName) public object[] DoFile(string fileName)
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
if(LuaDLL.luaL_loadfile(luaState,fileName)==0) if(KopiLua.Lua.luaL_loadfile(luaState,fileName)==0)
{ {
executing = true; executing = true;
try try
{ {
if (LuaDLL.lua_pcall(luaState, 0, -1, 0) == 0) if (KopiLua.Lua.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop); return translator.popValues(luaState, oldTop);
else else
ThrowExceptionFromError(oldTop); ThrowExceptionFromError(oldTop);
...@@ -362,9 +362,9 @@ namespace LuaInterface ...@@ -362,9 +362,9 @@ namespace LuaInterface
get get
{ {
object returnValue=null; object returnValue=null;
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
string[] path=fullPath.Split(new char[] { '.' }); string[] path=fullPath.Split(new char[] { '.' });
LuaDLL.lua_getglobal(luaState,path[0]); KopiLua.Lua.lua_getglobal(luaState,path[0]);
returnValue=translator.getObject(luaState,-1); returnValue=translator.getObject(luaState,-1);
if(path.Length>1) if(path.Length>1)
{ {
...@@ -372,26 +372,26 @@ namespace LuaInterface ...@@ -372,26 +372,26 @@ namespace LuaInterface
Array.Copy(path,1,remainingPath,0,path.Length-1); Array.Copy(path,1,remainingPath,0,path.Length-1);
returnValue=getObject(remainingPath); returnValue=getObject(remainingPath);
} }
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
return returnValue; return returnValue;
} }
set set
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
string[] path=fullPath.Split(new char[] { '.' }); string[] path=fullPath.Split(new char[] { '.' });
if(path.Length==1) if(path.Length==1)
{ {
translator.push(luaState,value); translator.push(luaState,value);
LuaDLL.lua_setglobal(luaState,fullPath); KopiLua.Lua.lua_setglobal(luaState,fullPath);
} }
else else
{ {
LuaDLL.lua_getglobal(luaState,path[0]); KopiLua.Lua.lua_getglobal(luaState,path[0]);
string[] remainingPath=new string[path.Length-1]; string[] remainingPath=new string[path.Length-1];
Array.Copy(path,1,remainingPath,0,path.Length-1); Array.Copy(path,1,remainingPath,0,path.Length-1);
setObject(remainingPath,value); setObject(remainingPath,value);
} }
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
// Globals auto-complete // Globals auto-complete
if (value == null) if (value == null)
...@@ -440,7 +440,7 @@ namespace LuaInterface ...@@ -440,7 +440,7 @@ namespace LuaInterface
private void registerGlobal(string path, Type type, int recursionCounter) private void registerGlobal(string path, Type type, int recursionCounter)
{ {
// If the type is a global method, list it directly // If the type is a global method, list it directly
if (type == typeof(LuaCSFunction)) if (type == typeof(KopiLua.Lua.lua_CFunction))
{ {
// Format for easy method invocation // Format for easy method invocation
globals.Add(path + "("); globals.Add(path + "(");
...@@ -519,8 +519,8 @@ namespace LuaInterface ...@@ -519,8 +519,8 @@ namespace LuaInterface
object returnValue=null; object returnValue=null;
for(int i=0;i<remainingPath.Length;i++) for(int i=0;i<remainingPath.Length;i++)
{ {
LuaDLL.lua_pushstring(luaState,remainingPath[i]); KopiLua.Lua.lua_pushstring(luaState,remainingPath[i]);
LuaDLL.lua_gettable(luaState,-2); KopiLua.Lua.lua_gettable(luaState,-2);
returnValue=translator.getObject(luaState,-1); returnValue=translator.getObject(luaState,-1);
if(returnValue==null) break; if(returnValue==null) break;
} }
...@@ -561,7 +561,8 @@ namespace LuaInterface ...@@ -561,7 +561,8 @@ namespace LuaInterface
public LuaFunction GetFunction(string fullPath) public LuaFunction GetFunction(string fullPath)
{ {
object obj=this[fullPath]; object obj=this[fullPath];
return (obj is LuaCSFunction ? new LuaFunction((LuaCSFunction)obj,this) : (LuaFunction)obj); //return (obj is KopiLua.Lua.lua_CFunction ? new LuaFunction((KopiLua.Lua.lua_CFunction)obj,this) : (LuaFunction)obj);
return (obj is KopiLua.Lua.lua_CFunction ? new LuaFunction((KopiLua.Lua.lua_CFunction)obj,this) : /*(LuaFunction)*/new LuaFunction(obj.GetHashCode(), this));
} }
/* /*
* Gets a function global variable as a delegate of * Gets a function global variable as a delegate of
...@@ -589,8 +590,8 @@ namespace LuaInterface ...@@ -589,8 +590,8 @@ namespace LuaInterface
internal object[] callFunction(object function,object[] args,Type[] returnTypes) internal object[] callFunction(object function,object[] args,Type[] returnTypes)
{ {
int nArgs=0; int nArgs=0;
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
if(!LuaDLL.lua_checkstack(luaState,args.Length+6)) if(!KopiLua.Lua.lua_checkstack(luaState,args.Length+6).ToBoolean())
throw new LuaException("Lua stack overflow"); throw new LuaException("Lua stack overflow");
translator.push(luaState,function); translator.push(luaState,function);
if(args!=null) if(args!=null)
...@@ -604,7 +605,7 @@ namespace LuaInterface ...@@ -604,7 +605,7 @@ namespace LuaInterface
executing = true; executing = true;
try try
{ {
int error = LuaDLL.lua_pcall(luaState, nArgs, -1, 0); int error = KopiLua.Lua.lua_pcall(luaState, nArgs, -1, 0);
if (error != 0) if (error != 0)
ThrowExceptionFromError(oldTop); ThrowExceptionFromError(oldTop);
} }
...@@ -622,12 +623,12 @@ namespace LuaInterface ...@@ -622,12 +623,12 @@ namespace LuaInterface
{ {
for(int i=0; i<remainingPath.Length-1;i++) for(int i=0; i<remainingPath.Length-1;i++)
{ {
LuaDLL.lua_pushstring(luaState,remainingPath[i]); KopiLua.Lua.lua_pushstring(luaState,remainingPath[i]);
LuaDLL.lua_gettable(luaState,-2); KopiLua.Lua.lua_gettable(luaState,-2);
} }
LuaDLL.lua_pushstring(luaState,remainingPath[remainingPath.Length-1]); KopiLua.Lua.lua_pushstring(luaState,remainingPath[remainingPath.Length-1]);
translator.push(luaState,val); translator.push(luaState,val);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
} }
/* /*
* Creates a new table as a global variable or as a field * Creates a new table as a global variable or as a field
...@@ -636,40 +637,40 @@ namespace LuaInterface ...@@ -636,40 +637,40 @@ namespace LuaInterface
public void NewTable(string fullPath) public void NewTable(string fullPath)
{ {
string[] path=fullPath.Split(new char[] { '.' }); string[] path=fullPath.Split(new char[] { '.' });
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
if(path.Length==1) if(path.Length==1)
{ {
LuaDLL.lua_newtable(luaState); KopiLua.Lua.lua_newtable(luaState);
LuaDLL.lua_setglobal(luaState,fullPath); KopiLua.Lua.lua_setglobal(luaState,fullPath);
} }
else else
{ {
LuaDLL.lua_getglobal(luaState,path[0]); KopiLua.Lua.lua_getglobal(luaState,path[0]);
for(int i=1; i<path.Length-1;i++) for(int i=1; i<path.Length-1;i++)
{ {
LuaDLL.lua_pushstring(luaState,path[i]); KopiLua.Lua.lua_pushstring(luaState,path[i]);
LuaDLL.lua_gettable(luaState,-2); KopiLua.Lua.lua_gettable(luaState,-2);
} }
LuaDLL.lua_pushstring(luaState,path[path.Length-1]); KopiLua.Lua.lua_pushstring(luaState,path[path.Length-1]);
LuaDLL.lua_newtable(luaState); KopiLua.Lua.lua_newtable(luaState);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
} }
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
} }
public ListDictionary GetTableDict(LuaTable table) public ListDictionary GetTableDict(LuaTable table)
{ {
ListDictionary dict = new ListDictionary(); ListDictionary dict = new ListDictionary();
int oldTop = LuaDLL.lua_gettop(luaState); int oldTop = KopiLua.Lua.lua_gettop(luaState);
translator.push(luaState, table); translator.push(luaState, table);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
while (LuaDLL.lua_next(luaState, -2) != 0) while (KopiLua.Lua.lua_next(luaState, -2) != 0)
{ {
dict[translator.getObject(luaState, -2)] = translator.getObject(luaState, -1); dict[translator.getObject(luaState, -2)] = translator.getObject(luaState, -1);
LuaDLL.lua_settop(luaState, -2); KopiLua.Lua.lua_settop(luaState, -2);
} }
LuaDLL.lua_settop(luaState, oldTop); KopiLua.Lua.lua_settop(luaState, oldTop);
return dict; return dict;
} }
...@@ -685,7 +686,7 @@ namespace LuaInterface ...@@ -685,7 +686,7 @@ namespace LuaInterface
/// lua hook calback delegate /// lua hook calback delegate
/// </summary> /// </summary>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
private LuaHookFunction hookCallback = null; private KopiLua.Lua.lua_Hook hookCallback = null;
/// <summary> /// <summary>
/// Activates the debug hook /// Activates the debug hook
...@@ -694,15 +695,15 @@ namespace LuaInterface ...@@ -694,15 +695,15 @@ namespace LuaInterface
/// <param name="count">Count</param> /// <param name="count">Count</param>
/// <returns>see lua docs. -1 if hook is already set</returns> /// <returns>see lua docs. -1 if hook is already set</returns>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public int SetDebugHook(EventMasks mask, int count) /*public int SetDebugHook(EventMasks mask, int count)
{ {
if (hookCallback == null) if (hookCallback == null)
{ {
hookCallback = new LuaHookFunction(DebugHookCallback); hookCallback = new KopiLua.Lua.lua_Hook(DebugHookCallback);
return LuaDLL.lua_sethook(luaState, hookCallback, (int)mask, count); return KopiLua.Lua.lua_sethook(luaState, hookCallback, (int)mask, count);
} }
return -1; return -1;
} }*/
/// <summary> /// <summary>
/// Removes the debug hook /// Removes the debug hook
...@@ -712,7 +713,7 @@ namespace LuaInterface ...@@ -712,7 +713,7 @@ namespace LuaInterface
public int RemoveDebugHook() public int RemoveDebugHook()
{ {
hookCallback = null; hookCallback = null;
return LuaDLL.lua_sethook(luaState, null, 0, 0); return KopiLua.Lua.lua_sethook(luaState, null, 0, 0);
} }
/// <summary> /// <summary>
...@@ -722,7 +723,7 @@ namespace LuaInterface ...@@ -722,7 +723,7 @@ namespace LuaInterface
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public EventMasks GetHookMask() public EventMasks GetHookMask()
{ {
return (EventMasks)LuaDLL.lua_gethookmask(luaState); return (EventMasks)KopiLua.Lua.lua_gethookmask(luaState);
} }
/// <summary> /// <summary>
...@@ -732,7 +733,7 @@ namespace LuaInterface ...@@ -732,7 +733,7 @@ namespace LuaInterface
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public int GetHookCount() public int GetHookCount()
{ {
return LuaDLL.lua_gethookcount(luaState); return KopiLua.Lua.lua_gethookcount(luaState);
} }
/// <summary> /// <summary>
...@@ -742,21 +743,21 @@ namespace LuaInterface ...@@ -742,21 +743,21 @@ namespace LuaInterface
/// <param name="luaDebug">lua debug structure</param> /// <param name="luaDebug">lua debug structure</param>
/// <returns>Returns true if level was allowed, false if level was invalid.</returns> /// <returns>Returns true if level was allowed, false if level was invalid.</returns>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public bool GetStack(int level, out LuaDebug luaDebug) /*public bool GetStack(int level, out LuaDebug luaDebug)
{ {
luaDebug = new LuaDebug(); luaDebug = new LuaDebug();
IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug)); KopiLua.Lua.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false); System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try try
{ {
return LuaDLL.lua_getstack(luaState, level, ld) != 0; return KopiLua.Lua.lua_getstack(luaState, level, ld) != 0;
} }
finally finally
{ {
luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug)); luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug));
System.Runtime.InteropServices.Marshal.FreeHGlobal(ld); System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
} }
} }*/
/// <summary> /// <summary>
/// Gets info (see lua docs) /// Gets info (see lua docs)
...@@ -765,20 +766,20 @@ namespace LuaInterface ...@@ -765,20 +766,20 @@ namespace LuaInterface
/// <param name="luaDebug">lua debug structure</param> /// <param name="luaDebug">lua debug structure</param>
/// <returns>see lua docs</returns> /// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public int GetInfo(String what, ref LuaDebug luaDebug) /*public int GetInfo(String what, ref LuaDebug luaDebug)
{ {
IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug)); KopiLua.Lua.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false); System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try try
{ {
return LuaDLL.lua_getinfo(luaState, what, ld); return KopiLua.Lua.lua_getinfo(luaState, what, ld);
} }
finally finally
{ {
luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug)); luaDebug = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(ld, typeof(LuaDebug));
System.Runtime.InteropServices.Marshal.FreeHGlobal(ld); System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
} }
} }*/
/// <summary> /// <summary>
/// Gets local (see lua docs) /// Gets local (see lua docs)
...@@ -787,19 +788,19 @@ namespace LuaInterface ...@@ -787,19 +788,19 @@ namespace LuaInterface
/// <param name="n">see lua docs</param> /// <param name="n">see lua docs</param>
/// <returns>see lua docs</returns> /// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public String GetLocal(LuaDebug luaDebug, int n) /*public String GetLocal(LuaDebug luaDebug, int n)
{ {
IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug)); KopiLua.Lua.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false); System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try try
{ {
return LuaDLL.lua_getlocal(luaState, ld, n); return KopiLua.Lua.lua_getlocal(luaState, ld, n);
} }
finally finally
{ {
System.Runtime.InteropServices.Marshal.FreeHGlobal(ld); System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
} }
} }*/
/// <summary> /// <summary>
/// Sets local (see lua docs) /// Sets local (see lua docs)
...@@ -808,19 +809,19 @@ namespace LuaInterface ...@@ -808,19 +809,19 @@ namespace LuaInterface
/// <param name="n">see lua docs</param> /// <param name="n">see lua docs</param>
/// <returns>see lua docs</returns> /// <returns>see lua docs</returns>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public String SetLocal(LuaDebug luaDebug, int n) /*public String SetLocal(LuaDebug luaDebug, int n)
{ {
IntPtr ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug)); KopiLua.Lua.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false); System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try try
{ {
return LuaDLL.lua_setlocal(luaState, ld, n); return KopiLua.Lua.lua_setlocal(luaState, ld, n);
} }
finally finally
{ {
System.Runtime.InteropServices.Marshal.FreeHGlobal(ld); System.Runtime.InteropServices.Marshal.FreeHGlobal(ld);
} }
} }*/
/// <summary> /// <summary>
/// Gets up value (see lua docs) /// Gets up value (see lua docs)
...@@ -831,7 +832,7 @@ namespace LuaInterface ...@@ -831,7 +832,7 @@ namespace LuaInterface
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public String GetUpValue(int funcindex, int n) public String GetUpValue(int funcindex, int n)
{ {
return LuaDLL.lua_getupvalue(luaState, funcindex, n); return KopiLua.Lua.lua_getupvalue(luaState, funcindex, n).ToString();
} }
/// <summary> /// <summary>
...@@ -843,7 +844,7 @@ namespace LuaInterface ...@@ -843,7 +844,7 @@ namespace LuaInterface
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public String SetUpValue(int funcindex, int n) public String SetUpValue(int funcindex, int n)
{ {
return LuaDLL.lua_setupvalue(luaState, funcindex, n); return KopiLua.Lua.lua_setupvalue(luaState, funcindex, n).ToString();
} }
/// <summary> /// <summary>
...@@ -852,7 +853,7 @@ namespace LuaInterface ...@@ -852,7 +853,7 @@ namespace LuaInterface
/// <param name="luaState">lua state</param> /// <param name="luaState">lua state</param>
/// <param name="luaDebug">Pointer to LuaDebug (lua_debug) structure</param> /// <param name="luaDebug">Pointer to LuaDebug (lua_debug) structure</param>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
private void DebugHookCallback(IntPtr luaState, IntPtr luaDebug) /*private void DebugHookCallback(KopiLua.Lua.lua_State luaState, KopiLua.Lua.lua_Debug luaDebug)
{ {
try try
{ {
...@@ -867,7 +868,7 @@ namespace LuaInterface ...@@ -867,7 +868,7 @@ namespace LuaInterface
{ {
OnHookException(new HookExceptionEventArgs(ex)); OnHookException(new HookExceptionEventArgs(ex));
} }
} }*/
/// <summary> /// <summary>
/// Event that is raised when an exception occures during a hook call. /// Event that is raised when an exception occures during a hook call.
...@@ -899,7 +900,7 @@ namespace LuaInterface ...@@ -899,7 +900,7 @@ namespace LuaInterface
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public object Pop() public object Pop()
{ {
int top = Lua511.LuaDLL.lua_gettop(luaState); int top = KopiLua.Lua.lua_gettop(luaState);
return translator.popValues(luaState, top - 1)[0]; return translator.popValues(luaState, top - 1)[0];
} }
...@@ -917,8 +918,9 @@ namespace LuaInterface ...@@ -917,8 +918,9 @@ namespace LuaInterface
internal void dispose(int reference) internal void dispose(int reference)
{ {
if (luaState != IntPtr.Zero) //Fix submitted by Qingrui Li ///////////// if (luaState != KopiLua.Lua.lua_State.Zero)
LuaDLL.lua_unref(luaState,reference); if (luaState != null) //Fix submitted by Qingrui Li
LuaLib.lua_unref(luaState,reference);
} }
/* /*
* Gets a field of the table corresponding to the provided reference * Gets a field of the table corresponding to the provided reference
...@@ -926,12 +928,12 @@ namespace LuaInterface ...@@ -926,12 +928,12 @@ namespace LuaInterface
*/ */
internal object rawGetObject(int reference,string field) internal object rawGetObject(int reference,string field)
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
LuaDLL.lua_getref(luaState,reference); LuaLib.lua_getref(luaState,reference);
LuaDLL.lua_pushstring(luaState,field); KopiLua.Lua.lua_pushstring(luaState,field);
LuaDLL.lua_rawget(luaState,-2); KopiLua.Lua.lua_rawget(luaState,-2);
object obj=translator.getObject(luaState,-1); object obj=translator.getObject(luaState,-1);
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
return obj; return obj;
} }
/* /*
...@@ -939,10 +941,10 @@ namespace LuaInterface ...@@ -939,10 +941,10 @@ namespace LuaInterface
*/ */
internal object getObject(int reference,string field) internal object getObject(int reference,string field)
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
LuaDLL.lua_getref(luaState,reference); LuaLib.lua_getref(luaState,reference);
object returnValue=getObject(field.Split(new char[] {'.'})); object returnValue=getObject(field.Split(new char[] {'.'}));
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
return returnValue; return returnValue;
} }
/* /*
...@@ -950,12 +952,12 @@ namespace LuaInterface ...@@ -950,12 +952,12 @@ namespace LuaInterface
*/ */
internal object getObject(int reference,object field) internal object getObject(int reference,object field)
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
LuaDLL.lua_getref(luaState,reference); LuaLib.lua_getref(luaState,reference);
translator.push(luaState,field); translator.push(luaState,field);
LuaDLL.lua_gettable(luaState,-2); KopiLua.Lua.lua_gettable(luaState,-2);
object returnValue=translator.getObject(luaState,-1); object returnValue=translator.getObject(luaState,-1);
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
return returnValue; return returnValue;
} }
/* /*
...@@ -964,10 +966,10 @@ namespace LuaInterface ...@@ -964,10 +966,10 @@ namespace LuaInterface
*/ */
internal void setObject(int reference, string field, object val) internal void setObject(int reference, string field, object val)
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
LuaDLL.lua_getref(luaState,reference); LuaLib.lua_getref(luaState,reference);
setObject(field.Split(new char[] {'.'}),val); setObject(field.Split(new char[] {'.'}),val);
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
} }
/* /*
* Sets a numeric field of the table or userdata corresponding the the provided reference * Sets a numeric field of the table or userdata corresponding the the provided reference
...@@ -975,12 +977,12 @@ namespace LuaInterface ...@@ -975,12 +977,12 @@ namespace LuaInterface
*/ */
internal void setObject(int reference, object field, object val) internal void setObject(int reference, object field, object val)
{ {
int oldTop=LuaDLL.lua_gettop(luaState); int oldTop=KopiLua.Lua.lua_gettop(luaState);
LuaDLL.lua_getref(luaState,reference); LuaLib.lua_getref(luaState,reference);
translator.push(luaState,field); translator.push(luaState,field);
translator.push(luaState,val); translator.push(luaState,val);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
} }
/* /*
...@@ -990,15 +992,15 @@ namespace LuaInterface ...@@ -990,15 +992,15 @@ namespace LuaInterface
public LuaFunction RegisterFunction(string path, object target, MethodBase function /*MethodInfo function*/) //CP: Fix for struct constructor by Alexander Kappner (link: http://luaforge.net/forum/forum.php?thread_id=2859&forum_id=145) public LuaFunction RegisterFunction(string path, object target, MethodBase function /*MethodInfo function*/) //CP: Fix for struct constructor by Alexander Kappner (link: http://luaforge.net/forum/forum.php?thread_id=2859&forum_id=145)
{ {
// We leave nothing on the stack when we are done // We leave nothing on the stack when we are done
int oldTop = LuaDLL.lua_gettop(luaState); int oldTop = KopiLua.Lua.lua_gettop(luaState);
LuaMethodWrapper wrapper=new LuaMethodWrapper(translator,target,function.DeclaringType,function); LuaMethodWrapper wrapper=new LuaMethodWrapper(translator,target,function.DeclaringType,function);
translator.push(luaState,new LuaCSFunction(wrapper.call)); translator.push(luaState,new KopiLua.Lua.lua_CFunction(wrapper.call));
this[path]=translator.getObject(luaState,-1); this[path]=translator.getObject(luaState,-1);
LuaFunction f = GetFunction(path); LuaFunction f = GetFunction(path);
LuaDLL.lua_settop(luaState, oldTop); KopiLua.Lua.lua_settop(luaState, oldTop);
return f; return f;
} }
...@@ -1009,15 +1011,15 @@ namespace LuaInterface ...@@ -1009,15 +1011,15 @@ namespace LuaInterface
*/ */
internal bool compareRef(int ref1, int ref2) internal bool compareRef(int ref1, int ref2)
{ {
int top=LuaDLL.lua_gettop(luaState); int top=KopiLua.Lua.lua_gettop(luaState);
LuaDLL.lua_getref(luaState,ref1); LuaLib.lua_getref(luaState,ref1);
LuaDLL.lua_getref(luaState,ref2); LuaLib.lua_getref(luaState,ref2);
int equal=LuaDLL.lua_equal(luaState,-1,-2); int equal=KopiLua.Lua.lua_equal(luaState,-1,-2);
LuaDLL.lua_settop(luaState,top); KopiLua.Lua.lua_settop(luaState,top);
return (equal!=0); return (equal!=0);
} }
internal void pushCSFunction(LuaCSFunction function) internal void pushCSFunction(KopiLua.Lua.lua_CFunction function)
{ {
translator.pushFunction(luaState,function); translator.pushFunction(luaState,function);
} }
......
...@@ -10,15 +10,19 @@ namespace LuaInterface ...@@ -10,15 +10,19 @@ namespace LuaInterface
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);
} }
......
...@@ -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))
{ {
......
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()
{ {
......
...@@ -6,8 +6,8 @@ namespace LuaInterface ...@@ -6,8 +6,8 @@ namespace LuaInterface
using System.Reflection; using System.Reflection;
using System.Diagnostics; using System.Diagnostics;
using System.Collections.Generic; using System.Collections.Generic;
using Lua511;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using LuaWrap;
/* /*
* Functions used in the metatables of userdata representing * Functions used in the metatables of userdata representing
...@@ -39,39 +39,39 @@ namespace LuaInterface ...@@ -39,39 +39,39 @@ namespace LuaInterface
private ObjectTranslator translator; private ObjectTranslator translator;
private Hashtable memberCache = new Hashtable(); private Hashtable memberCache = new Hashtable();
internal LuaCSFunction gcFunction, indexFunction, newindexFunction, internal KopiLua.Lua.lua_CFunction gcFunction, indexFunction, newindexFunction,
baseIndexFunction, classIndexFunction, classNewindexFunction, baseIndexFunction, classIndexFunction, classNewindexFunction,
execDelegateFunction, callConstructorFunction, toStringFunction; execDelegateFunction, callConstructorFunction, toStringFunction;
public MetaFunctions(ObjectTranslator translator) public MetaFunctions(ObjectTranslator translator)
{ {
this.translator = translator; this.translator = translator;
gcFunction = new LuaCSFunction(this.collectObject); gcFunction = new KopiLua.Lua.lua_CFunction(this.collectObject);
toStringFunction = new LuaCSFunction(this.toString); toStringFunction = new KopiLua.Lua.lua_CFunction(this.toString);
indexFunction = new LuaCSFunction(this.getMethod); indexFunction = new KopiLua.Lua.lua_CFunction(this.getMethod);
newindexFunction = new LuaCSFunction(this.setFieldOrProperty); newindexFunction = new KopiLua.Lua.lua_CFunction(this.setFieldOrProperty);
baseIndexFunction = new LuaCSFunction(this.getBaseMethod); baseIndexFunction = new KopiLua.Lua.lua_CFunction(this.getBaseMethod);
callConstructorFunction = new LuaCSFunction(this.callConstructor); callConstructorFunction = new KopiLua.Lua.lua_CFunction(this.callConstructor);
classIndexFunction = new LuaCSFunction(this.getClassMethod); classIndexFunction = new KopiLua.Lua.lua_CFunction(this.getClassMethod);
classNewindexFunction = new LuaCSFunction(this.setClassFieldOrProperty); classNewindexFunction = new KopiLua.Lua.lua_CFunction(this.setClassFieldOrProperty);
execDelegateFunction = new LuaCSFunction(this.runFunctionDelegate); execDelegateFunction = new KopiLua.Lua.lua_CFunction(this.runFunctionDelegate);
} }
/* /*
* __call metafunction of CLR delegates, retrieves and calls the delegate. * __call metafunction of CLR delegates, retrieves and calls the delegate.
*/ */
private int runFunctionDelegate(IntPtr luaState) private int runFunctionDelegate(KopiLua.Lua.lua_State luaState)
{ {
LuaCSFunction func = (LuaCSFunction)translator.getRawNetObject(luaState, 1); KopiLua.Lua.lua_CFunction func = (KopiLua.Lua.lua_CFunction)translator.getRawNetObject(luaState, 1);
LuaDLL.lua_remove(luaState, 1); KopiLua.Lua.lua_remove(luaState, 1);
return func(luaState); return func(luaState);
} }
/* /*
* __gc metafunction of CLR objects. * __gc metafunction of CLR objects.
*/ */
private int collectObject(IntPtr luaState) private int collectObject(KopiLua.Lua.lua_State luaState)
{ {
int udata = LuaDLL.luanet_rawnetobj(luaState, 1); int udata = LuaLib.luanet_rawnetobj(luaState, 1);
if (udata != -1) if (udata != -1)
{ {
translator.collectObject(udata); translator.collectObject(udata);
...@@ -85,14 +85,14 @@ namespace LuaInterface ...@@ -85,14 +85,14 @@ namespace LuaInterface
/* /*
* __tostring metafunction of CLR objects. * __tostring metafunction of CLR objects.
*/ */
private int toString(IntPtr luaState) private int toString(KopiLua.Lua.lua_State luaState)
{ {
object obj = translator.getRawNetObject(luaState, 1); object obj = translator.getRawNetObject(luaState, 1);
if (obj != null) if (obj != null)
{ {
translator.push(luaState, obj.ToString() + ": " + obj.GetHashCode()); translator.push(luaState, obj.ToString() + ": " + obj.GetHashCode());
} }
else LuaDLL.lua_pushnil(luaState); else KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
...@@ -101,19 +101,19 @@ namespace LuaInterface ...@@ -101,19 +101,19 @@ namespace LuaInterface
/// Debug tool to dump the lua stack /// Debug tool to dump the lua stack
/// </summary> /// </summary>
/// FIXME, move somewhere else /// FIXME, move somewhere else
public static void dumpStack(ObjectTranslator translator, IntPtr luaState) public static void dumpStack(ObjectTranslator translator, KopiLua.Lua.lua_State luaState)
{ {
int depth = LuaDLL.lua_gettop(luaState); int depth = KopiLua.Lua.lua_gettop(luaState);
Debug.WriteLine("lua stack depth: " + depth); Debug.WriteLine("lua stack depth: " + depth);
for (int i = 1; i <= depth; i++) for (int i = 1; i <= depth; i++)
{ {
LuaTypes type = LuaDLL.lua_type(luaState, i); LuaTypes type = KopiLua.Lua.lua_type(luaState, i).ToLuaTypes();
// we dump stacks when deep in calls, calling typename while the stack is in flux can fail sometimes, so manually check for key types // we dump stacks when deep in calls, calling typename while the stack is in flux can fail sometimes, so manually check for key types
string typestr = (type == LuaTypes.LUA_TTABLE) ? "table" : LuaDLL.lua_typename(luaState, type); string typestr = (type == LuaTypes.Table) ? "table" : KopiLua.Lua.lua_typename(luaState, Convert.ToInt32(type)).ToString();
string strrep = LuaDLL.lua_tostring(luaState, i); string strrep = KopiLua.Lua.lua_tostring(luaState, i).ToString();
if (type == LuaTypes.LUA_TUSERDATA) if (type == LuaTypes.UserData)
{ {
object obj = translator.getRawNetObject(luaState, i); object obj = translator.getRawNetObject(luaState, i);
strrep = obj.ToString(); strrep = obj.ToString();
...@@ -131,13 +131,13 @@ namespace LuaInterface ...@@ -131,13 +131,13 @@ namespace LuaInterface
* either the value of the member or a delegate to call it. * either the value of the member or a delegate to call it.
* If the member does not exist returns nil. * If the member does not exist returns nil.
*/ */
private int getMethod(IntPtr luaState) private int getMethod(KopiLua.Lua.lua_State luaState)
{ {
object obj = translator.getRawNetObject(luaState, 1); object obj = translator.getRawNetObject(luaState, 1);
if (obj == null) if (obj == null)
{ {
translator.throwError(luaState, "trying to index an invalid object reference"); translator.throwError(luaState, "trying to index an invalid object reference");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
...@@ -204,7 +204,7 @@ namespace LuaInterface ...@@ -204,7 +204,7 @@ namespace LuaInterface
{ {
translator.throwError(luaState, "method not found (or no indexer): " + index); translator.throwError(luaState, "method not found (or no indexer): " + index);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
else else
{ {
...@@ -228,7 +228,7 @@ namespace LuaInterface ...@@ -228,7 +228,7 @@ namespace LuaInterface
else else
translator.throwError(luaState, "exception indexing '" + index + "' " + e.Message); translator.throwError(luaState, "exception indexing '" + index + "' " + e.Message);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
} }
} }
...@@ -238,7 +238,7 @@ namespace LuaInterface ...@@ -238,7 +238,7 @@ namespace LuaInterface
} }
LuaDLL.lua_pushboolean(luaState, false); KopiLua.Lua.lua_pushboolean(luaState, 0);
return 2; return 2;
} }
...@@ -247,31 +247,31 @@ namespace LuaInterface ...@@ -247,31 +247,31 @@ namespace LuaInterface
* __index metafunction of base classes (the base field of Lua tables). * __index metafunction of base classes (the base field of Lua tables).
* Adds a prefix to the method name to call the base version of the method. * Adds a prefix to the method name to call the base version of the method.
*/ */
private int getBaseMethod(IntPtr luaState) private int getBaseMethod(KopiLua.Lua.lua_State luaState)
{ {
object obj = translator.getRawNetObject(luaState, 1); object obj = translator.getRawNetObject(luaState, 1);
if (obj == null) if (obj == null)
{ {
translator.throwError(luaState, "trying to index an invalid object reference"); translator.throwError(luaState, "trying to index an invalid object reference");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
LuaDLL.lua_pushboolean(luaState, false); KopiLua.Lua.lua_pushboolean(luaState, 0);
return 2; return 2;
} }
string methodName = LuaDLL.lua_tostring(luaState, 2); string methodName = KopiLua.Lua.lua_tostring(luaState, 2).ToString();
if (methodName == null) if (methodName == null)
{ {
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
LuaDLL.lua_pushboolean(luaState, false); KopiLua.Lua.lua_pushboolean(luaState, 0);
return 2; return 2;
} }
getMember(luaState, obj.GetType(), obj, "__luaInterface_base_" + methodName, BindingFlags.Instance | BindingFlags.IgnoreCase); getMember(luaState, obj.GetType(), obj, "__luaInterface_base_" + methodName, BindingFlags.Instance | BindingFlags.IgnoreCase);
LuaDLL.lua_settop(luaState, -2); KopiLua.Lua.lua_settop(luaState, -2);
if (LuaDLL.lua_type(luaState, -1) == LuaTypes.LUA_TNIL) if (KopiLua.Lua.lua_type(luaState, -1).ToLuaTypes() == LuaTypes.Nil)
{ {
LuaDLL.lua_settop(luaState, -2); KopiLua.Lua.lua_settop(luaState, -2);
return getMember(luaState, obj.GetType(), obj, methodName, BindingFlags.Instance | BindingFlags.IgnoreCase); return getMember(luaState, obj.GetType(), obj, methodName, BindingFlags.Instance | BindingFlags.IgnoreCase);
} }
LuaDLL.lua_pushboolean(luaState, false); KopiLua.Lua.lua_pushboolean(luaState, 0);
return 2; return 2;
} }
...@@ -300,15 +300,15 @@ namespace LuaInterface ...@@ -300,15 +300,15 @@ namespace LuaInterface
* Uses reflection to find members, and stores the reflected MemberInfo object in * Uses reflection to find members, and stores the reflected MemberInfo object in
* a cache (indexed by the type of the object and the name of the member). * a cache (indexed by the type of the object and the name of the member).
*/ */
private int getMember(IntPtr luaState, IReflect objType, object obj, string methodName, BindingFlags bindingType) private int getMember(KopiLua.Lua.lua_State luaState, IReflect objType, object obj, string methodName, BindingFlags bindingType)
{ {
bool implicitStatic = false; bool implicitStatic = false;
MemberInfo member = null; MemberInfo member = null;
object cachedMember = checkMemberCache(memberCache, objType, methodName); object cachedMember = checkMemberCache(memberCache, objType, methodName);
//object cachedMember=null; //object cachedMember=null;
if (cachedMember is LuaCSFunction) if (cachedMember is KopiLua.Lua.lua_CFunction)
{ {
translator.pushFunction(luaState, (LuaCSFunction)cachedMember); translator.pushFunction(luaState, (KopiLua.Lua.lua_CFunction)cachedMember);
translator.push(luaState, true); translator.push(luaState, true);
return 2; return 2;
} }
...@@ -348,7 +348,7 @@ namespace LuaInterface ...@@ -348,7 +348,7 @@ namespace LuaInterface
} }
catch catch
{ {
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
} }
else if (member.MemberType == MemberTypes.Property) else if (member.MemberType == MemberTypes.Property)
...@@ -369,12 +369,12 @@ namespace LuaInterface ...@@ -369,12 +369,12 @@ namespace LuaInterface
if (objType is Type && !(((Type)objType) == typeof(object))) if (objType is Type && !(((Type)objType) == typeof(object)))
return getMember(luaState, ((Type)objType).BaseType, obj, methodName, bindingType); return getMember(luaState, ((Type)objType).BaseType, obj, methodName, bindingType);
else else
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
catch (TargetInvocationException e) // Convert this exception into a Lua error catch (TargetInvocationException e) // Convert this exception into a Lua error
{ {
ThrowError(luaState, e); ThrowError(luaState, e);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
} }
else if (member.MemberType == MemberTypes.Event) else if (member.MemberType == MemberTypes.Event)
...@@ -405,7 +405,7 @@ namespace LuaInterface ...@@ -405,7 +405,7 @@ namespace LuaInterface
else else
{ {
// Member type must be 'method' // Member type must be 'method'
LuaCSFunction wrapper = new LuaCSFunction((new LuaMethodWrapper(translator, objType, methodName, bindingType)).call); KopiLua.Lua.lua_CFunction wrapper = new KopiLua.Lua.lua_CFunction((new LuaMethodWrapper(translator, objType, methodName, bindingType)).call);
if (cachedMember == null) setMemberCache(memberCache, objType, methodName, wrapper); if (cachedMember == null) setMemberCache(memberCache, objType, methodName, wrapper);
translator.pushFunction(luaState, wrapper); translator.pushFunction(luaState, wrapper);
...@@ -418,7 +418,7 @@ namespace LuaInterface ...@@ -418,7 +418,7 @@ namespace LuaInterface
// If we reach this point we found a static method, but can't use it in this context because the user passed in an instance // If we reach this point we found a static method, but can't use it in this context because the user passed in an instance
translator.throwError(luaState, "can't pass instance to static method " + methodName); translator.throwError(luaState, "can't pass instance to static method " + methodName);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
} }
else else
...@@ -429,7 +429,7 @@ namespace LuaInterface ...@@ -429,7 +429,7 @@ namespace LuaInterface
translator.throwError(luaState, "unknown member name " + methodName); translator.throwError(luaState, "unknown member name " + methodName);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
// push false because we are NOT returning a function (see luaIndexFunction) // push false because we are NOT returning a function (see luaIndexFunction)
...@@ -465,7 +465,7 @@ namespace LuaInterface ...@@ -465,7 +465,7 @@ namespace LuaInterface
* the member name and the value to be stored as arguments. Throws * the member name and the value to be stored as arguments. Throws
* and error if the assignment is invalid. * and error if the assignment is invalid.
*/ */
private int setFieldOrProperty(IntPtr luaState) private int setFieldOrProperty(KopiLua.Lua.lua_State luaState)
{ {
object target = translator.getRawNetObject(luaState, 1); object target = translator.getRawNetObject(luaState, 1);
if (target == null) if (target == null)
...@@ -485,9 +485,9 @@ namespace LuaInterface ...@@ -485,9 +485,9 @@ namespace LuaInterface
// We didn't find a property name, now see if we can use a [] style this accessor to set array contents // We didn't find a property name, now see if we can use a [] style this accessor to set array contents
try try
{ {
if (type.IsArray && LuaDLL.lua_isnumber(luaState, 2)) if (type.IsArray && KopiLua.Lua.lua_isnumber(luaState, 2).ToBoolean())
{ {
int index = (int)LuaDLL.lua_tonumber(luaState, 2); int index = (int)KopiLua.Lua.lua_tonumber(luaState, 2);
Array arr = (Array)target; Array arr = (Array)target;
object val = translator.getAsType(luaState, 3, arr.GetType().GetElementType()); object val = translator.getAsType(luaState, 3, arr.GetType().GetElementType());
...@@ -542,7 +542,7 @@ namespace LuaInterface ...@@ -542,7 +542,7 @@ namespace LuaInterface
/// <param name="target"></param> /// <param name="target"></param>
/// <param name="bindingType"></param> /// <param name="bindingType"></param>
/// <returns>false if unable to find the named member, true for success</returns> /// <returns>false if unable to find the named member, true for success</returns>
private bool trySetMember(IntPtr luaState, IReflect targetType, object target, BindingFlags bindingType, out string detailMessage) private bool trySetMember(KopiLua.Lua.lua_State luaState, IReflect targetType, object target, BindingFlags bindingType, out string detailMessage)
{ {
detailMessage = null; // No error yet detailMessage = null; // No error yet
...@@ -550,14 +550,14 @@ namespace LuaInterface ...@@ -550,14 +550,14 @@ namespace LuaInterface
// changing the lua typecode to string // changing the lua typecode to string
// Note: We don't use isstring because the standard lua C isstring considers either strings or numbers to // Note: We don't use isstring because the standard lua C isstring considers either strings or numbers to
// be true for isstring. // be true for isstring.
if (LuaDLL.lua_type(luaState, 2) != LuaTypes.LUA_TSTRING) if (KopiLua.Lua.lua_type(luaState, 2).ToLuaTypes() != LuaTypes.String)
{ {
detailMessage = "property names must be strings"; detailMessage = "property names must be strings";
return false; return false;
} }
// We only look up property names by string // We only look up property names by string
string fieldName = LuaDLL.lua_tostring(luaState, 2); string fieldName = KopiLua.Lua.lua_tostring(luaState, 2).ToString();
if (fieldName == null || fieldName.Length < 1 || !(char.IsLetter(fieldName[0]) || fieldName[0] == '_')) if (fieldName == null || fieldName.Length < 1 || !(char.IsLetter(fieldName[0]) || fieldName[0] == '_'))
{ {
detailMessage = "invalid property name"; detailMessage = "invalid property name";
...@@ -622,7 +622,7 @@ namespace LuaInterface ...@@ -622,7 +622,7 @@ namespace LuaInterface
* Writes to fields or properties, either static or instance. Throws an error * Writes to fields or properties, either static or instance. Throws an error
* if the operation is invalid. * if the operation is invalid.
*/ */
private int setMember(IntPtr luaState, IReflect targetType, object target, BindingFlags bindingType) private int setMember(KopiLua.Lua.lua_State luaState, IReflect targetType, object target, BindingFlags bindingType)
{ {
string detail; string detail;
bool success = trySetMember(luaState, targetType, target, bindingType, out detail); bool success = trySetMember(luaState, targetType, target, bindingType, out detail);
...@@ -638,7 +638,7 @@ namespace LuaInterface ...@@ -638,7 +638,7 @@ namespace LuaInterface
/// </summary> /// </summary>
/// <param name="e"></param> /// <param name="e"></param>
/// We try to look into the exception to give the most meaningful description /// We try to look into the exception to give the most meaningful description
void ThrowError(IntPtr luaState, Exception e) void ThrowError(KopiLua.Lua.lua_State luaState, Exception e)
{ {
// If we got inside a reflection show what really happened // If we got inside a reflection show what really happened
TargetInvocationException te = e as TargetInvocationException; TargetInvocationException te = e as TargetInvocationException;
...@@ -652,29 +652,29 @@ namespace LuaInterface ...@@ -652,29 +652,29 @@ namespace LuaInterface
/* /*
* __index metafunction of type references, works on static members. * __index metafunction of type references, works on static members.
*/ */
private int getClassMethod(IntPtr luaState) private int getClassMethod(KopiLua.Lua.lua_State luaState)
{ {
IReflect klass; IReflect klass;
object obj = translator.getRawNetObject(luaState, 1); object obj = translator.getRawNetObject(luaState, 1);
if (obj == null || !(obj is IReflect)) if (obj == null || !(obj is IReflect))
{ {
translator.throwError(luaState, "trying to index an invalid type reference"); translator.throwError(luaState, "trying to index an invalid type reference");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
else klass = (IReflect)obj; else klass = (IReflect)obj;
if (LuaDLL.lua_isnumber(luaState, 2)) if (KopiLua.Lua.lua_isnumber(luaState, 2).ToBoolean())
{ {
int size = (int)LuaDLL.lua_tonumber(luaState, 2); int size = (int)KopiLua.Lua.lua_tonumber(luaState, 2);
translator.push(luaState, Array.CreateInstance(klass.UnderlyingSystemType, size)); translator.push(luaState, Array.CreateInstance(klass.UnderlyingSystemType, size));
return 1; return 1;
} }
else else
{ {
string methodName = LuaDLL.lua_tostring(luaState, 2); string methodName = KopiLua.Lua.lua_tostring(luaState, 2).ToString();
if (methodName == null) if (methodName == null)
{ {
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} //CP: Ignore case } //CP: Ignore case
else return getMember(luaState, klass, null, methodName, BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.IgnoreCase); else return getMember(luaState, klass, null, methodName, BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.IgnoreCase);
...@@ -683,7 +683,7 @@ namespace LuaInterface ...@@ -683,7 +683,7 @@ namespace LuaInterface
/* /*
* __newindex function of type references, works on static members. * __newindex function of type references, works on static members.
*/ */
private int setClassFieldOrProperty(IntPtr luaState) private int setClassFieldOrProperty(KopiLua.Lua.lua_State luaState)
{ {
IReflect target; IReflect target;
object obj = translator.getRawNetObject(luaState, 1); object obj = translator.getRawNetObject(luaState, 1);
...@@ -701,7 +701,7 @@ namespace LuaInterface ...@@ -701,7 +701,7 @@ namespace LuaInterface
* found or if the arguments are invalid. Throws an error if the constructor * found or if the arguments are invalid. Throws an error if the constructor
* generates an exception. * generates an exception.
*/ */
private int callConstructor(IntPtr luaState) private int callConstructor(KopiLua.Lua.lua_State luaState)
{ {
MethodCache validConstructor = new MethodCache(); MethodCache validConstructor = new MethodCache();
IReflect klass; IReflect klass;
...@@ -709,11 +709,11 @@ namespace LuaInterface ...@@ -709,11 +709,11 @@ namespace LuaInterface
if (obj == null || !(obj is IReflect)) if (obj == null || !(obj is IReflect))
{ {
translator.throwError(luaState, "trying to call constructor on an invalid type reference"); translator.throwError(luaState, "trying to call constructor on an invalid type reference");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
else klass = (IReflect)obj; else klass = (IReflect)obj;
LuaDLL.lua_remove(luaState, 1); KopiLua.Lua.lua_remove(luaState, 1);
ConstructorInfo[] constructors = klass.UnderlyingSystemType.GetConstructors(); ConstructorInfo[] constructors = klass.UnderlyingSystemType.GetConstructors();
foreach (ConstructorInfo constructor in constructors) foreach (ConstructorInfo constructor in constructors)
{ {
...@@ -727,11 +727,11 @@ namespace LuaInterface ...@@ -727,11 +727,11 @@ namespace LuaInterface
catch (TargetInvocationException e) catch (TargetInvocationException e)
{ {
ThrowError(luaState, e); ThrowError(luaState, e);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
catch catch
{ {
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
return 1; return 1;
} }
...@@ -742,7 +742,7 @@ namespace LuaInterface ...@@ -742,7 +742,7 @@ namespace LuaInterface
translator.throwError(luaState, String.Format("{0} does not contain constructor({1}) argument match", translator.throwError(luaState, String.Format("{0} does not contain constructor({1}) argument match",
klass.UnderlyingSystemType, klass.UnderlyingSystemType,
constructorName)); constructorName));
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
/* /*
...@@ -750,13 +750,13 @@ namespace LuaInterface ...@@ -750,13 +750,13 @@ namespace LuaInterface
* if the match was succesful. It it was also returns the information * if the match was succesful. It it was also returns the information
* necessary to invoke the method. * necessary to invoke the method.
*/ */
internal bool matchParameters(IntPtr luaState, MethodBase method, ref MethodCache methodCache) internal bool matchParameters(KopiLua.Lua.lua_State luaState, MethodBase method, ref MethodCache methodCache)
{ {
ExtractValue extractValue; ExtractValue extractValue;
bool isMethod = true; bool isMethod = true;
ParameterInfo[] paramInfo = method.GetParameters(); ParameterInfo[] paramInfo = method.GetParameters();
int currentLuaParam = 1; int currentLuaParam = 1;
int nLuaParams = LuaDLL.lua_gettop(luaState); int nLuaParams = KopiLua.Lua.lua_gettop(luaState);
ArrayList paramList = new ArrayList(); ArrayList paramList = new ArrayList();
List<int> outList = new List<int>(); List<int> outList = new List<int>();
List<MethodArgs> argTypes = new List<MethodArgs>(); List<MethodArgs> argTypes = new List<MethodArgs>();
...@@ -864,7 +864,7 @@ namespace LuaInterface ...@@ -864,7 +864,7 @@ namespace LuaInterface
/// <param name="currentNetParam"></param> /// <param name="currentNetParam"></param>
/// <param name="extractValue"></param> /// <param name="extractValue"></param>
/// <returns></returns> /// <returns></returns>
private bool _IsTypeCorrect(IntPtr luaState, int currentLuaParam, ParameterInfo currentNetParam, out ExtractValue extractValue) private bool _IsTypeCorrect(KopiLua.Lua.lua_State luaState, int currentLuaParam, ParameterInfo currentNetParam, out ExtractValue extractValue)
{ {
try try
{ {
...@@ -878,7 +878,7 @@ namespace LuaInterface ...@@ -878,7 +878,7 @@ namespace LuaInterface
} }
} }
private bool _IsParamsArray(IntPtr luaState, int currentLuaParam, ParameterInfo currentNetParam, out ExtractValue extractValue) private bool _IsParamsArray(KopiLua.Lua.lua_State luaState, int currentLuaParam, ParameterInfo currentNetParam, out ExtractValue extractValue)
{ {
extractValue = null; extractValue = null;
...@@ -888,7 +888,7 @@ namespace LuaInterface ...@@ -888,7 +888,7 @@ namespace LuaInterface
try try
{ {
luaType = LuaDLL.lua_type(luaState, currentLuaParam); luaType = KopiLua.Lua.lua_type(luaState, currentLuaParam).ToLuaTypes();
} }
catch (Exception ex) catch (Exception ex)
{ {
...@@ -898,13 +898,13 @@ namespace LuaInterface ...@@ -898,13 +898,13 @@ namespace LuaInterface
return false; return false;
} }
if (luaType == LuaTypes.LUA_TTABLE) if (luaType == LuaTypes.Table)
{ {
try try
{ {
extractValue = translator.typeChecker.getExtractor(typeof(LuaTable)); extractValue = translator.typeChecker.getExtractor(typeof(LuaTable));
} }
catch (Exception ex) catch (Exception/* ex*/)
{ {
Debug.WriteLine("An error occurred during an attempt to retrieve a LuaTable extractor while checking for params array status."); Debug.WriteLine("An error occurred during an attempt to retrieve a LuaTable extractor while checking for params array status.");
} }
...@@ -922,7 +922,7 @@ namespace LuaInterface ...@@ -922,7 +922,7 @@ namespace LuaInterface
{ {
extractValue = translator.typeChecker.checkType(luaState, currentLuaParam, paramElementType); extractValue = translator.typeChecker.checkType(luaState, currentLuaParam, paramElementType);
} }
catch (Exception ex) catch (Exception/* ex*/)
{ {
Debug.WriteLine(string.Format("An error occurred during an attempt to retrieve an extractor ({0}) while checking for params array status.", paramElementType.FullName)); Debug.WriteLine(string.Format("An error occurred during an attempt to retrieve an extractor ({0}) while checking for params array status.", paramElementType.FullName));
} }
......
...@@ -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
{ {
......
...@@ -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;
/* /*
* Passes objects from the CLR to Lua and vice-versa * Passes objects from the CLR to Lua and vice-versa
...@@ -25,24 +25,24 @@ namespace LuaInterface ...@@ -25,24 +25,24 @@ namespace LuaInterface
internal Lua interpreter; internal Lua interpreter;
private MetaFunctions metaFunctions; private MetaFunctions metaFunctions;
private List<Assembly> assemblies; private List<Assembly> assemblies;
private LuaCSFunction registerTableFunction,unregisterTableFunction,getMethodSigFunction, private KopiLua.Lua.lua_CFunction registerTableFunction,unregisterTableFunction,getMethodSigFunction,
getConstructorSigFunction,importTypeFunction,loadAssemblyFunction; getConstructorSigFunction,importTypeFunction,loadAssemblyFunction;
internal EventHandlerContainer pendingEvents = new EventHandlerContainer(); internal EventHandlerContainer pendingEvents = new EventHandlerContainer();
public ObjectTranslator(Lua interpreter,IntPtr luaState) public ObjectTranslator(Lua interpreter,KopiLua.Lua.lua_State luaState)
{ {
this.interpreter=interpreter; this.interpreter=interpreter;
typeChecker=new CheckType(this); typeChecker=new CheckType(this);
metaFunctions=new MetaFunctions(this); metaFunctions=new MetaFunctions(this);
assemblies=new List<Assembly>(); assemblies=new List<Assembly>();
importTypeFunction=new LuaCSFunction(this.importType); importTypeFunction=new KopiLua.Lua.lua_CFunction(this.importType);
loadAssemblyFunction=new LuaCSFunction(this.loadAssembly); loadAssemblyFunction=new KopiLua.Lua.lua_CFunction(this.loadAssembly);
registerTableFunction=new LuaCSFunction(this.registerTable); registerTableFunction=new KopiLua.Lua.lua_CFunction(this.registerTable);
unregisterTableFunction=new LuaCSFunction(this.unregisterTable); unregisterTableFunction=new KopiLua.Lua.lua_CFunction(this.unregisterTable);
getMethodSigFunction=new LuaCSFunction(this.getMethodSignature); getMethodSigFunction=new KopiLua.Lua.lua_CFunction(this.getMethodSignature);
getConstructorSigFunction=new LuaCSFunction(this.getConstructorSignature); getConstructorSigFunction=new KopiLua.Lua.lua_CFunction(this.getConstructorSignature);
createLuaObjectList(luaState); createLuaObjectList(luaState);
createIndexingMetaFunction(luaState); createIndexingMetaFunction(luaState);
...@@ -55,117 +55,117 @@ namespace LuaInterface ...@@ -55,117 +55,117 @@ namespace LuaInterface
/* /*
* Sets up the list of objects in the Lua side * Sets up the list of objects in the Lua side
*/ */
private void createLuaObjectList(IntPtr luaState) private void createLuaObjectList(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.lua_pushstring(luaState,"luaNet_objects"); KopiLua.Lua.lua_pushstring(luaState,"luaNet_objects");
LuaDLL.lua_newtable(luaState); KopiLua.Lua.lua_newtable(luaState);
LuaDLL.lua_newtable(luaState); KopiLua.Lua.lua_newtable(luaState);
LuaDLL.lua_pushstring(luaState,"__mode"); KopiLua.Lua.lua_pushstring(luaState,"__mode");
LuaDLL.lua_pushstring(luaState,"v"); KopiLua.Lua.lua_pushstring(luaState,"v");
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_setmetatable(luaState,-2); KopiLua.Lua.lua_setmetatable(luaState,-2);
LuaDLL.lua_settable(luaState, (int) LuaIndexes.LUA_REGISTRYINDEX); KopiLua.Lua.lua_settable(luaState, (int) PseudoIndex.Registry);
} }
/* /*
* Registers the indexing function of CLR objects * Registers the indexing function of CLR objects
* passed to Lua * passed to Lua
*/ */
private void createIndexingMetaFunction(IntPtr luaState) private void createIndexingMetaFunction(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.lua_pushstring(luaState,"luaNet_indexfunction"); KopiLua.Lua.lua_pushstring(luaState,"luaNet_indexfunction");
LuaDLL.luaL_dostring(luaState,MetaFunctions.luaIndexFunction); // steffenj: lua_dostring renamed to luaL_dostring LuaLib.luaL_dostring(luaState,MetaFunctions.luaIndexFunction); // steffenj: lua_dostring renamed to luaL_dostring
//LuaDLL.lua_pushstdcallcfunction(luaState,indexFunction); //LuaLib.lua_pushstdcallcfunction(luaState,indexFunction);
LuaDLL.lua_rawset(luaState, (int) LuaIndexes.LUA_REGISTRYINDEX); KopiLua.Lua.lua_rawset(luaState, (int) PseudoIndex.Registry);
} }
/* /*
* Creates the metatable for superclasses (the base * Creates the metatable for superclasses (the base
* field of registered tables) * field of registered tables)
*/ */
private void createBaseClassMetatable(IntPtr luaState) private void createBaseClassMetatable(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.luaL_newmetatable(luaState,"luaNet_searchbase"); KopiLua.Lua.luaL_newmetatable(luaState,"luaNet_searchbase");
LuaDLL.lua_pushstring(luaState,"__gc"); KopiLua.Lua.lua_pushstring(luaState,"__gc");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__tostring"); KopiLua.Lua.lua_pushstring(luaState,"__tostring");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__index"); KopiLua.Lua.lua_pushstring(luaState,"__index");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.baseIndexFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.baseIndexFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__newindex"); KopiLua.Lua.lua_pushstring(luaState,"__newindex");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.newindexFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.newindexFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_settop(luaState,-2); KopiLua.Lua.lua_settop(luaState,-2);
} }
/* /*
* Creates the metatable for type references * Creates the metatable for type references
*/ */
private void createClassMetatable(IntPtr luaState) private void createClassMetatable(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.luaL_newmetatable(luaState,"luaNet_class"); KopiLua.Lua.luaL_newmetatable(luaState,"luaNet_class");
LuaDLL.lua_pushstring(luaState,"__gc"); KopiLua.Lua.lua_pushstring(luaState,"__gc");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__tostring"); KopiLua.Lua.lua_pushstring(luaState,"__tostring");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__index"); KopiLua.Lua.lua_pushstring(luaState,"__index");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.classIndexFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.classIndexFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__newindex"); KopiLua.Lua.lua_pushstring(luaState,"__newindex");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.classNewindexFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.classNewindexFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__call"); KopiLua.Lua.lua_pushstring(luaState,"__call");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.callConstructorFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.callConstructorFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_settop(luaState,-2); KopiLua.Lua.lua_settop(luaState,-2);
} }
/* /*
* Registers the global functions used by LuaInterface * Registers the global functions used by LuaInterface
*/ */
private void setGlobalFunctions(IntPtr luaState) private void setGlobalFunctions(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.indexFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.indexFunction);
LuaDLL.lua_setglobal(luaState,"get_object_member"); KopiLua.Lua.lua_setglobal(luaState,"get_object_member");
LuaDLL.lua_pushstdcallcfunction(luaState,importTypeFunction); LuaLib.lua_pushstdcallcfunction(luaState,importTypeFunction);
LuaDLL.lua_setglobal(luaState,"import_type"); KopiLua.Lua.lua_setglobal(luaState,"import_type");
LuaDLL.lua_pushstdcallcfunction(luaState,loadAssemblyFunction); LuaLib.lua_pushstdcallcfunction(luaState,loadAssemblyFunction);
LuaDLL.lua_setglobal(luaState,"load_assembly"); KopiLua.Lua.lua_setglobal(luaState,"load_assembly");
LuaDLL.lua_pushstdcallcfunction(luaState,registerTableFunction); LuaLib.lua_pushstdcallcfunction(luaState,registerTableFunction);
LuaDLL.lua_setglobal(luaState,"make_object"); KopiLua.Lua.lua_setglobal(luaState,"make_object");
LuaDLL.lua_pushstdcallcfunction(luaState,unregisterTableFunction); LuaLib.lua_pushstdcallcfunction(luaState,unregisterTableFunction);
LuaDLL.lua_setglobal(luaState,"free_object"); KopiLua.Lua.lua_setglobal(luaState,"free_object");
LuaDLL.lua_pushstdcallcfunction(luaState,getMethodSigFunction); LuaLib.lua_pushstdcallcfunction(luaState,getMethodSigFunction);
LuaDLL.lua_setglobal(luaState,"get_method_bysig"); KopiLua.Lua.lua_setglobal(luaState,"get_method_bysig");
LuaDLL.lua_pushstdcallcfunction(luaState,getConstructorSigFunction); LuaLib.lua_pushstdcallcfunction(luaState,getConstructorSigFunction);
LuaDLL.lua_setglobal(luaState,"get_constructor_bysig"); KopiLua.Lua.lua_setglobal(luaState,"get_constructor_bysig");
} }
/* /*
* Creates the metatable for delegates * Creates the metatable for delegates
*/ */
private void createFunctionMetatable(IntPtr luaState) private void createFunctionMetatable(KopiLua.Lua.lua_State luaState)
{ {
LuaDLL.luaL_newmetatable(luaState,"luaNet_function"); KopiLua.Lua.luaL_newmetatable(luaState,"luaNet_function");
LuaDLL.lua_pushstring(luaState,"__gc"); KopiLua.Lua.lua_pushstring(luaState,"__gc");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__call"); KopiLua.Lua.lua_pushstring(luaState,"__call");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.execDelegateFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.execDelegateFunction);
LuaDLL.lua_settable(luaState,-3); KopiLua.Lua.lua_settable(luaState,-3);
LuaDLL.lua_settop(luaState,-2); KopiLua.Lua.lua_settop(luaState,-2);
} }
/* /*
* Passes errors (argument e) to the Lua interpreter * Passes errors (argument e) to the Lua interpreter
*/ */
internal void throwError(IntPtr luaState, object e) internal void throwError(KopiLua.Lua.lua_State luaState, object e)
{ {
// We use this to remove anything pushed by luaL_where // We use this to remove anything pushed by luaL_where
int oldTop = LuaDLL.lua_gettop(luaState); int oldTop = KopiLua.Lua.lua_gettop(luaState);
// Stack frame #1 is our C# wrapper, so not very interesting to the user // 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 // Stack frame #2 must be the lua code that called us, so that's what we want to use
LuaDLL.luaL_where(luaState, 1); KopiLua.Lua.luaL_where(luaState, 1);
object[] curlev = popValues(luaState, oldTop); object[] curlev = popValues(luaState, oldTop);
// Determine the position in the script where the exception was triggered // Determine the position in the script where the exception was triggered
...@@ -190,17 +190,17 @@ namespace LuaInterface ...@@ -190,17 +190,17 @@ namespace LuaInterface
} }
push(luaState, e); push(luaState, e);
LuaDLL.lua_error(luaState); KopiLua.Lua.lua_error(luaState);
} }
/* /*
* Implementation of load_assembly. Throws an error * Implementation of load_assembly. Throws an error
* if the assembly is not found. * if the assembly is not found.
*/ */
private int loadAssembly(IntPtr luaState) private int loadAssembly(KopiLua.Lua.lua_State luaState)
{ {
try try
{ {
string assemblyName=LuaDLL.lua_tostring(luaState,1); string assemblyName=KopiLua.Lua.lua_tostring(luaState,1).ToString();
Assembly assembly = null; Assembly assembly = null;
...@@ -248,14 +248,14 @@ namespace LuaInterface ...@@ -248,14 +248,14 @@ namespace LuaInterface
* Implementation of import_type. Returns nil if the * Implementation of import_type. Returns nil if the
* type is not found. * type is not found.
*/ */
private int importType(IntPtr luaState) private int importType(KopiLua.Lua.lua_State luaState)
{ {
string className=LuaDLL.lua_tostring(luaState,1); string className=KopiLua.Lua.lua_tostring(luaState,1).ToString();
Type klass=FindType(className); Type klass=FindType(className);
if(klass!=null) if(klass!=null)
pushType(luaState,klass); pushType(luaState,klass);
else else
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
/* /*
...@@ -263,12 +263,12 @@ namespace LuaInterface ...@@ -263,12 +263,12 @@ namespace LuaInterface
* argument in the stack) as an object subclassing the * argument in the stack) as an object subclassing the
* type passed as second argument in the stack. * type passed as second argument in the stack.
*/ */
private int registerTable(IntPtr luaState) private int registerTable(KopiLua.Lua.lua_State luaState)
{ {
if(LuaDLL.lua_type(luaState,1)==LuaTypes.LUA_TTABLE) if(KopiLua.Lua.lua_type(luaState,1).ToLuaTypes()==LuaTypes.Table)
{ {
LuaTable luaTable=getTable(luaState,1); LuaTable luaTable=getTable(luaState,1);
string superclassName = LuaDLL.lua_tostring(luaState, 2); string superclassName = KopiLua.Lua.lua_tostring(luaState, 2).ToString();
if (superclassName != null) if (superclassName != null)
{ {
Type klass = FindType(superclassName); Type klass = FindType(superclassName);
...@@ -278,20 +278,20 @@ namespace LuaInterface ...@@ -278,20 +278,20 @@ namespace LuaInterface
// it as the metatable of the first argument // it as the metatable of the first argument
object obj = CodeGeneration.Instance.GetClassInstance(klass, luaTable); object obj = CodeGeneration.Instance.GetClassInstance(klass, luaTable);
pushObject(luaState, obj, "luaNet_metatable"); pushObject(luaState, obj, "luaNet_metatable");
LuaDLL.lua_newtable(luaState); KopiLua.Lua.lua_newtable(luaState);
LuaDLL.lua_pushstring(luaState, "__index"); KopiLua.Lua.lua_pushstring(luaState, "__index");
LuaDLL.lua_pushvalue(luaState, -3); KopiLua.Lua.lua_pushvalue(luaState, -3);
LuaDLL.lua_settable(luaState, -3); KopiLua.Lua.lua_settable(luaState, -3);
LuaDLL.lua_pushstring(luaState, "__newindex"); KopiLua.Lua.lua_pushstring(luaState, "__newindex");
LuaDLL.lua_pushvalue(luaState, -3); KopiLua.Lua.lua_pushvalue(luaState, -3);
LuaDLL.lua_settable(luaState, -3); KopiLua.Lua.lua_settable(luaState, -3);
LuaDLL.lua_setmetatable(luaState, 1); KopiLua.Lua.lua_setmetatable(luaState, 1);
// Pushes the object again, this time as the base field // Pushes the object again, this time as the base field
// of the table and with the luaNet_searchbase metatable // of the table and with the luaNet_searchbase metatable
LuaDLL.lua_pushstring(luaState, "base"); KopiLua.Lua.lua_pushstring(luaState, "base");
int index = addObject(obj); int index = addObject(obj);
pushNewObject(luaState, obj, index, "luaNet_searchbase"); pushNewObject(luaState, obj, index, "luaNet_searchbase");
LuaDLL.lua_rawset(luaState, 1); KopiLua.Lua.lua_rawset(luaState, 1);
} }
else else
throwError(luaState, "register_table: can not find superclass '" + superclassName + "'"); throwError(luaState, "register_table: can not find superclass '" + superclassName + "'");
...@@ -306,24 +306,24 @@ namespace LuaInterface ...@@ -306,24 +306,24 @@ namespace LuaInterface
* Implementation of free_object. Clears the metatable and the * Implementation of free_object. Clears the metatable and the
* base field, freeing the created object for garbage-collection * base field, freeing the created object for garbage-collection
*/ */
private int unregisterTable(IntPtr luaState) private int unregisterTable(KopiLua.Lua.lua_State luaState)
{ {
try try
{ {
if(LuaDLL.lua_getmetatable(luaState,1)!=0) if(KopiLua.Lua.lua_getmetatable(luaState,1)!=0)
{ {
LuaDLL.lua_pushstring(luaState,"__index"); KopiLua.Lua.lua_pushstring(luaState,"__index");
LuaDLL.lua_gettable(luaState,-2); KopiLua.Lua.lua_gettable(luaState,-2);
object obj=getRawNetObject(luaState,-1); object obj=getRawNetObject(luaState,-1);
if(obj==null) throwError(luaState,"unregister_table: arg is not valid table"); if(obj==null) throwError(luaState,"unregister_table: arg is not valid table");
FieldInfo luaTableField=obj.GetType().GetField("__luaInterface_luaTable"); FieldInfo luaTableField=obj.GetType().GetField("__luaInterface_luaTable");
if(luaTableField==null) throwError(luaState,"unregister_table: arg is not valid table"); if(luaTableField==null) throwError(luaState,"unregister_table: arg is not valid table");
luaTableField.SetValue(obj,null); luaTableField.SetValue(obj,null);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
LuaDLL.lua_setmetatable(luaState,1); KopiLua.Lua.lua_setmetatable(luaState,1);
LuaDLL.lua_pushstring(luaState,"base"); KopiLua.Lua.lua_pushstring(luaState,"base");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
LuaDLL.lua_settable(luaState,1); KopiLua.Lua.lua_settable(luaState,1);
} }
else throwError(luaState,"unregister_table: arg is not valid table"); else throwError(luaState,"unregister_table: arg is not valid table");
} }
...@@ -337,10 +337,10 @@ namespace LuaInterface ...@@ -337,10 +337,10 @@ namespace LuaInterface
* Implementation of get_method_bysig. Returns nil * Implementation of get_method_bysig. Returns nil
* if no matching method is not found. * if no matching method is not found.
*/ */
private int getMethodSignature(IntPtr luaState) private int getMethodSignature(KopiLua.Lua.lua_State luaState)
{ {
IReflect klass; object target; IReflect klass; object target;
int udata=LuaDLL.luanet_checkudata(luaState,1,"luaNet_class"); int udata=LuaLib.luanet_checkudata(luaState,1,"luaNet_class");
if(udata!=-1) if(udata!=-1)
{ {
klass=(IReflect)objects[udata]; klass=(IReflect)objects[udata];
...@@ -352,26 +352,26 @@ namespace LuaInterface ...@@ -352,26 +352,26 @@ namespace LuaInterface
if(target==null) if(target==null)
{ {
throwError(luaState,"get_method_bysig: first arg is not type or object reference"); throwError(luaState,"get_method_bysig: first arg is not type or object reference");
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return 1; return 1;
} }
klass=target.GetType(); klass=target.GetType();
} }
string methodName=LuaDLL.lua_tostring(luaState,2); string methodName=KopiLua.Lua.lua_tostring(luaState,2).ToString();
Type[] signature=new Type[LuaDLL.lua_gettop(luaState)-2]; Type[] signature=new Type[KopiLua.Lua.lua_gettop(luaState)-2];
for(int i=0;i<signature.Length;i++) for(int i=0;i<signature.Length;i++)
signature[i]=FindType(LuaDLL.lua_tostring(luaState,i+3)); signature[i]=FindType(KopiLua.Lua.lua_tostring(luaState,i+3).ToString());
try try
{ {
//CP: Added ignore case //CP: Added ignore case
MethodInfo method=klass.GetMethod(methodName,BindingFlags.Public | BindingFlags.Static | MethodInfo method=klass.GetMethod(methodName,BindingFlags.Public | BindingFlags.Static |
BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase, null, signature, null); BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase, null, signature, null);
pushFunction(luaState,new LuaCSFunction((new LuaMethodWrapper(this,target,klass,method)).call)); pushFunction(luaState,new KopiLua.Lua.lua_CFunction((new LuaMethodWrapper(this,target,klass,method)).call));
} }
catch(Exception e) catch(Exception e)
{ {
throwError(luaState,e); throwError(luaState,e);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
return 1; return 1;
} }
...@@ -379,10 +379,10 @@ namespace LuaInterface ...@@ -379,10 +379,10 @@ namespace LuaInterface
* Implementation of get_constructor_bysig. Returns nil * Implementation of get_constructor_bysig. Returns nil
* if no matching constructor is found. * if no matching constructor is found.
*/ */
private int getConstructorSignature(IntPtr luaState) private int getConstructorSignature(KopiLua.Lua.lua_State luaState)
{ {
IReflect klass=null; IReflect klass=null;
int udata=LuaDLL.luanet_checkudata(luaState,1,"luaNet_class"); int udata=LuaLib.luanet_checkudata(luaState,1,"luaNet_class");
if(udata!=-1) if(udata!=-1)
{ {
klass=(IReflect)objects[udata]; klass=(IReflect)objects[udata];
...@@ -391,32 +391,32 @@ namespace LuaInterface ...@@ -391,32 +391,32 @@ namespace LuaInterface
{ {
throwError(luaState,"get_constructor_bysig: first arg is invalid type reference"); throwError(luaState,"get_constructor_bysig: first arg is invalid type reference");
} }
Type[] signature=new Type[LuaDLL.lua_gettop(luaState)-1]; Type[] signature=new Type[KopiLua.Lua.lua_gettop(luaState)-1];
for(int i=0;i<signature.Length;i++) for(int i=0;i<signature.Length;i++)
signature[i]=FindType(LuaDLL.lua_tostring(luaState,i+2)); signature[i]=FindType(KopiLua.Lua.lua_tostring(luaState,i+2).ToString());
try try
{ {
ConstructorInfo constructor=klass.UnderlyingSystemType.GetConstructor(signature); ConstructorInfo constructor=klass.UnderlyingSystemType.GetConstructor(signature);
pushFunction(luaState,new LuaCSFunction((new LuaMethodWrapper(this,null,klass,constructor)).call)); pushFunction(luaState,new KopiLua.Lua.lua_CFunction((new LuaMethodWrapper(this,null,klass,constructor)).call));
} }
catch(Exception e) catch(Exception e)
{ {
throwError(luaState,e); throwError(luaState,e);
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
return 1; return 1;
} }
/* /*
* Pushes a type reference into the stack * Pushes a type reference into the stack
*/ */
internal void pushType(IntPtr luaState, Type t) internal void pushType(KopiLua.Lua.lua_State luaState, Type t)
{ {
pushObject(luaState,new ProxyType(t),"luaNet_class"); pushObject(luaState,new ProxyType(t),"luaNet_class");
} }
/* /*
* Pushes a delegate into the stack * Pushes a delegate into the stack
*/ */
internal void pushFunction(IntPtr luaState, LuaCSFunction func) internal void pushFunction(KopiLua.Lua.lua_State luaState, KopiLua.Lua.lua_CFunction func)
{ {
pushObject(luaState,func,"luaNet_function"); pushObject(luaState,func,"luaNet_function");
} }
...@@ -424,13 +424,13 @@ namespace LuaInterface ...@@ -424,13 +424,13 @@ namespace LuaInterface
* Pushes a CLR object into the Lua stack as an userdata * Pushes a CLR object into the Lua stack as an userdata
* with the provided metatable * with the provided metatable
*/ */
internal void pushObject(IntPtr luaState, object o, string metatable) internal void pushObject(KopiLua.Lua.lua_State luaState, object o, string metatable)
{ {
int index = -1; int index = -1;
// Pushes nil // Pushes nil
if(o==null) if(o==null)
{ {
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
return; return;
} }
...@@ -438,25 +438,25 @@ namespace LuaInterface ...@@ -438,25 +438,25 @@ namespace LuaInterface
bool found = objectsBackMap.TryGetValue(o, out index); bool found = objectsBackMap.TryGetValue(o, out index);
if(found) if(found)
{ {
LuaDLL.luaL_getmetatable(luaState,"luaNet_objects"); KopiLua.Lua.luaL_getmetatable(luaState,"luaNet_objects");
LuaDLL.lua_rawgeti(luaState,-1,index); KopiLua.Lua.lua_rawgeti(luaState,-1,index);
// Note: starting with lua5.1 the garbage collector may remove weak reference items (such as our luaNet_objects values) when the initial GC sweep // 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 // 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 // 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 // object here
// did we find a non nil object in our table? if not, we need to call collect object // did we find a non nil object in our table? if not, we need to call collect object
LuaTypes type = LuaDLL.lua_type(luaState, -1); LuaTypes type = KopiLua.Lua.lua_type(luaState, -1).ToLuaTypes();
if (type != LuaTypes.LUA_TNIL) if (type != LuaTypes.Nil)
{ {
LuaDLL.lua_remove(luaState, -2); // drop the metatable - we're going to leave our object on the stack KopiLua.Lua.lua_remove(luaState, -2); // drop the metatable - we're going to leave our object on the stack
return; return;
} }
// MetaFunctions.dumpStack(this, luaState); // MetaFunctions.dumpStack(this, luaState);
LuaDLL.lua_remove(luaState, -1); // remove the nil object value KopiLua.Lua.lua_remove(luaState, -1); // remove the nil object value
LuaDLL.lua_remove(luaState, -1); // remove the metatable KopiLua.Lua.lua_remove(luaState, -1); // remove the metatable
collectObject(o, index); // Remove from both our tables and fall out to get a new ID collectObject(o, index); // Remove from both our tables and fall out to get a new ID
} }
...@@ -470,59 +470,59 @@ namespace LuaInterface ...@@ -470,59 +470,59 @@ namespace LuaInterface
* Pushes a new object into the Lua stack with the provided * Pushes a new object into the Lua stack with the provided
* metatable * metatable
*/ */
private void pushNewObject(IntPtr luaState,object o,int index,string metatable) private void pushNewObject(KopiLua.Lua.lua_State luaState,object o,int index,string metatable)
{ {
if(metatable=="luaNet_metatable") if(metatable=="luaNet_metatable")
{ {
// Gets or creates the metatable for the object's type // Gets or creates the metatable for the object's type
LuaDLL.luaL_getmetatable(luaState,o.GetType().AssemblyQualifiedName); KopiLua.Lua.luaL_getmetatable(luaState,o.GetType().AssemblyQualifiedName);
if(LuaDLL.lua_isnil(luaState,-1)) if(KopiLua.Lua.lua_isnil(luaState,-1))
{ {
LuaDLL.lua_settop(luaState,-2); KopiLua.Lua.lua_settop(luaState,-2);
LuaDLL.luaL_newmetatable(luaState,o.GetType().AssemblyQualifiedName); KopiLua.Lua.luaL_newmetatable(luaState,o.GetType().AssemblyQualifiedName);
LuaDLL.lua_pushstring(luaState,"cache"); KopiLua.Lua.lua_pushstring(luaState,"cache");
LuaDLL.lua_newtable(luaState); KopiLua.Lua.lua_newtable(luaState);
LuaDLL.lua_rawset(luaState,-3); KopiLua.Lua.lua_rawset(luaState,-3);
LuaDLL.lua_pushlightuserdata(luaState,LuaDLL.luanet_gettag()); KopiLua.Lua.lua_pushlightuserdata(luaState,LuaLib.luanet_gettag());
LuaDLL.lua_pushnumber(luaState,1); KopiLua.Lua.lua_pushnumber(luaState,1);
LuaDLL.lua_rawset(luaState,-3); KopiLua.Lua.lua_rawset(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__index"); KopiLua.Lua.lua_pushstring(luaState,"__index");
LuaDLL.lua_pushstring(luaState,"luaNet_indexfunction"); KopiLua.Lua.lua_pushstring(luaState,"luaNet_indexfunction");
LuaDLL.lua_rawget(luaState, (int) LuaIndexes.LUA_REGISTRYINDEX); KopiLua.Lua.lua_rawget(luaState, (int) PseudoIndex.Registry);
LuaDLL.lua_rawset(luaState,-3); KopiLua.Lua.lua_rawset(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__gc"); KopiLua.Lua.lua_pushstring(luaState,"__gc");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaDLL.lua_rawset(luaState,-3); KopiLua.Lua.lua_rawset(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__tostring"); KopiLua.Lua.lua_pushstring(luaState,"__tostring");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction);
LuaDLL.lua_rawset(luaState,-3); KopiLua.Lua.lua_rawset(luaState,-3);
LuaDLL.lua_pushstring(luaState,"__newindex"); KopiLua.Lua.lua_pushstring(luaState,"__newindex");
LuaDLL.lua_pushstdcallcfunction(luaState,metaFunctions.newindexFunction); LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.newindexFunction);
LuaDLL.lua_rawset(luaState,-3); KopiLua.Lua.lua_rawset(luaState,-3);
} }
} }
else else
{ {
LuaDLL.luaL_getmetatable(luaState,metatable); KopiLua.Lua.luaL_getmetatable(luaState,metatable);
} }
// Stores the object index in the Lua list and pushes the // Stores the object index in the Lua list and pushes the
// index into the Lua stack // index into the Lua stack
LuaDLL.luaL_getmetatable(luaState,"luaNet_objects"); KopiLua.Lua.luaL_getmetatable(luaState,"luaNet_objects");
LuaDLL.luanet_newudata(luaState,index); LuaLib.luanet_newudata(luaState,index);
LuaDLL.lua_pushvalue(luaState,-3); KopiLua.Lua.lua_pushvalue(luaState,-3);
LuaDLL.lua_remove(luaState,-4); KopiLua.Lua.lua_remove(luaState,-4);
LuaDLL.lua_setmetatable(luaState,-2); KopiLua.Lua.lua_setmetatable(luaState,-2);
LuaDLL.lua_pushvalue(luaState,-1); KopiLua.Lua.lua_pushvalue(luaState,-1);
LuaDLL.lua_rawseti(luaState,-3,index); KopiLua.Lua.lua_rawseti(luaState,-3,index);
LuaDLL.lua_remove(luaState,-2); KopiLua.Lua.lua_remove(luaState,-2);
} }
/* /*
* Gets an object from the Lua stack with the desired type, if it matches, otherwise * Gets an object from the Lua stack with the desired type, if it matches, otherwise
* returns null. * returns null.
*/ */
internal object getAsType(IntPtr luaState,int stackPos,Type paramType) internal object getAsType(KopiLua.Lua.lua_State luaState,int stackPos,Type paramType)
{ {
ExtractValue extractor=typeChecker.checkType(luaState,stackPos,paramType); ExtractValue extractor=typeChecker.checkType(luaState,stackPos,paramType);
if(extractor!=null) return extractor(luaState,stackPos); if(extractor!=null) return extractor(luaState,stackPos);
...@@ -586,34 +586,34 @@ namespace LuaInterface ...@@ -586,34 +586,34 @@ namespace LuaInterface
/* /*
* Gets an object from the Lua stack according to its Lua type. * Gets an object from the Lua stack according to its Lua type.
*/ */
internal object getObject(IntPtr luaState,int index) internal object getObject(KopiLua.Lua.lua_State luaState,int index)
{ {
LuaTypes type=LuaDLL.lua_type(luaState,index); LuaTypes type=KopiLua.Lua.lua_type(luaState,index).ToLuaTypes();
switch(type) switch(type)
{ {
case LuaTypes.LUA_TNUMBER: case LuaTypes.Number:
{ {
return LuaDLL.lua_tonumber(luaState,index); return KopiLua.Lua.lua_tonumber(luaState,index);
} }
case LuaTypes.LUA_TSTRING: case LuaTypes.String:
{ {
return LuaDLL.lua_tostring(luaState,index); return KopiLua.Lua.lua_tostring(luaState,index);
} }
case LuaTypes.LUA_TBOOLEAN: case LuaTypes.Boolean:
{ {
return LuaDLL.lua_toboolean(luaState,index); return KopiLua.Lua.lua_toboolean(luaState,index);
} }
case LuaTypes.LUA_TTABLE: case LuaTypes.Table:
{ {
return getTable(luaState,index); return getTable(luaState,index);
} }
case LuaTypes.LUA_TFUNCTION: case LuaTypes.Function:
{ {
return getFunction(luaState,index); return getFunction(luaState,index);
} }
case LuaTypes.LUA_TUSERDATA: case LuaTypes.UserData:
{ {
int udata=LuaDLL.luanet_tonetobject(luaState,index); int udata=LuaLib.luanet_tonetobject(luaState,index);
if(udata!=-1) if(udata!=-1)
return objects[udata]; return objects[udata];
else else
...@@ -626,34 +626,34 @@ namespace LuaInterface ...@@ -626,34 +626,34 @@ namespace LuaInterface
/* /*
* Gets the table in the index positon of the Lua stack. * Gets the table in the index positon of the Lua stack.
*/ */
internal LuaTable getTable(IntPtr luaState,int index) internal LuaTable getTable(KopiLua.Lua.lua_State luaState,int index)
{ {
LuaDLL.lua_pushvalue(luaState,index); KopiLua.Lua.lua_pushvalue(luaState,index);
return new LuaTable(LuaDLL.lua_ref(luaState,1),interpreter); return new LuaTable(LuaLib.lua_ref(luaState,1),interpreter);
} }
/* /*
* Gets the userdata in the index positon of the Lua stack. * Gets the userdata in the index positon of the Lua stack.
*/ */
internal LuaUserData getUserData(IntPtr luaState,int index) internal LuaUserData getUserData(KopiLua.Lua.lua_State luaState,int index)
{ {
LuaDLL.lua_pushvalue(luaState,index); KopiLua.Lua.lua_pushvalue(luaState,index);
return new LuaUserData(LuaDLL.lua_ref(luaState,1),interpreter); return new LuaUserData(LuaLib.lua_ref(luaState,1),interpreter);
} }
/* /*
* Gets the function in the index positon of the Lua stack. * Gets the function in the index positon of the Lua stack.
*/ */
internal LuaFunction getFunction(IntPtr luaState,int index) internal LuaFunction getFunction(KopiLua.Lua.lua_State luaState,int index)
{ {
LuaDLL.lua_pushvalue(luaState,index); KopiLua.Lua.lua_pushvalue(luaState,index);
return new LuaFunction(LuaDLL.lua_ref(luaState,1),interpreter); return new LuaFunction(LuaLib.lua_ref(luaState,1),interpreter);
} }
/* /*
* Gets the CLR object in the index positon of the Lua stack. Returns * Gets the CLR object in the index positon of the Lua stack. Returns
* delegates as Lua functions. * delegates as Lua functions.
*/ */
internal object getNetObject(IntPtr luaState,int index) internal object getNetObject(KopiLua.Lua.lua_State luaState,int index)
{ {
int idx=LuaDLL.luanet_tonetobject(luaState,index); int idx=LuaLib.luanet_tonetobject(luaState,index);
if(idx!=-1) if(idx!=-1)
return objects[idx]; return objects[idx];
else else
...@@ -663,9 +663,9 @@ namespace LuaInterface ...@@ -663,9 +663,9 @@ namespace LuaInterface
* Gets the CLR object in the index positon of the Lua stack. Returns * Gets the CLR object in the index positon of the Lua stack. Returns
* delegates as is. * delegates as is.
*/ */
internal object getRawNetObject(IntPtr luaState,int index) internal object getRawNetObject(KopiLua.Lua.lua_State luaState,int index)
{ {
int udata=LuaDLL.luanet_rawnetobj(luaState,index); int udata=LuaLib.luanet_rawnetobj(luaState,index);
if(udata!=-1) if(udata!=-1)
{ {
return objects[udata]; return objects[udata];
...@@ -676,9 +676,9 @@ namespace LuaInterface ...@@ -676,9 +676,9 @@ namespace LuaInterface
* Pushes the entire array into the Lua stack and returns the number * Pushes the entire array into the Lua stack and returns the number
* of elements pushed. * of elements pushed.
*/ */
internal int returnValues(IntPtr luaState, object[] returnValues) internal int returnValues(KopiLua.Lua.lua_State luaState, object[] returnValues)
{ {
if(LuaDLL.lua_checkstack(luaState,returnValues.Length+5)) if(KopiLua.Lua.lua_checkstack(luaState,returnValues.Length+5).ToBoolean())
{ {
for(int i=0;i<returnValues.Length;i++) for(int i=0;i<returnValues.Length;i++)
{ {
...@@ -692,9 +692,9 @@ namespace LuaInterface ...@@ -692,9 +692,9 @@ namespace LuaInterface
* Gets the values from the provided index to * Gets the values from the provided index to
* the top of the stack and returns them in an array. * the top of the stack and returns them in an array.
*/ */
internal object[] popValues(IntPtr luaState,int oldTop) internal object[] popValues(KopiLua.Lua.lua_State luaState,int oldTop)
{ {
int newTop=LuaDLL.lua_gettop(luaState); int newTop=KopiLua.Lua.lua_gettop(luaState);
if(oldTop==newTop) if(oldTop==newTop)
{ {
return null; return null;
...@@ -706,7 +706,7 @@ namespace LuaInterface ...@@ -706,7 +706,7 @@ namespace LuaInterface
{ {
returnValues.Add(getObject(luaState,i)); returnValues.Add(getObject(luaState,i));
} }
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
return returnValues.ToArray(); return returnValues.ToArray();
} }
} }
...@@ -715,9 +715,9 @@ namespace LuaInterface ...@@ -715,9 +715,9 @@ namespace LuaInterface
* the top of the stack and returns them in an array, casting * the top of the stack and returns them in an array, casting
* them to the provided types. * them to the provided types.
*/ */
internal object[] popValues(IntPtr luaState,int oldTop,Type[] popTypes) internal object[] popValues(KopiLua.Lua.lua_State luaState,int oldTop,Type[] popTypes)
{ {
int newTop=LuaDLL.lua_gettop(luaState); int newTop=KopiLua.Lua.lua_gettop(luaState);
if(oldTop==newTop) if(oldTop==newTop)
{ {
return null; return null;
...@@ -735,7 +735,7 @@ namespace LuaInterface ...@@ -735,7 +735,7 @@ namespace LuaInterface
returnValues.Add(getAsType(luaState,i,popTypes[iTypes])); returnValues.Add(getAsType(luaState,i,popTypes[iTypes]));
iTypes++; iTypes++;
} }
LuaDLL.lua_settop(luaState,oldTop); KopiLua.Lua.lua_settop(luaState,oldTop);
return returnValues.ToArray(); return returnValues.ToArray();
} }
} }
...@@ -758,33 +758,33 @@ namespace LuaInterface ...@@ -758,33 +758,33 @@ namespace LuaInterface
/* /*
* Pushes the object into the Lua stack according to its type. * Pushes the object into the Lua stack according to its type.
*/ */
internal void push(IntPtr luaState, object o) internal void push(KopiLua.Lua.lua_State luaState, object o)
{ {
if(o==null) if(o==null)
{ {
LuaDLL.lua_pushnil(luaState); KopiLua.Lua.lua_pushnil(luaState);
} }
else if(o is sbyte || o is byte || o is short || o is ushort || else if(o is sbyte || o is byte || o is short || o is ushort ||
o is int || o is uint || o is long || o is float || o is int || o is uint || o is long || o is float ||
o is ulong || o is decimal || o is double) o is ulong || o is decimal || o is double)
{ {
double d=Convert.ToDouble(o); double d=Convert.ToDouble(o);
LuaDLL.lua_pushnumber(luaState,d); KopiLua.Lua.lua_pushnumber(luaState,d);
} }
else if(o is char) else if(o is char)
{ {
double d = (char)o; double d = (char)o;
LuaDLL.lua_pushnumber(luaState,d); KopiLua.Lua.lua_pushnumber(luaState,d);
} }
else if(o is string) else if(o is string)
{ {
string str=(string)o; string str=(string)o;
LuaDLL.lua_pushstring(luaState,str); KopiLua.Lua.lua_pushstring(luaState,str);
} }
else if(o is bool) else if(o is bool)
{ {
bool b=(bool)o; bool b=(bool)o;
LuaDLL.lua_pushboolean(luaState,b); KopiLua.Lua.lua_pushboolean(luaState, (b == true ? 1 : 0));
} }
else if(IsILua(o)) else if(IsILua(o))
{ {
...@@ -794,9 +794,9 @@ namespace LuaInterface ...@@ -794,9 +794,9 @@ namespace LuaInterface
{ {
((LuaTable)o).push(luaState); ((LuaTable)o).push(luaState);
} }
else if(o is LuaCSFunction) else if(o is KopiLua.Lua.lua_CFunction)
{ {
pushFunction(luaState,(LuaCSFunction)o); pushFunction(luaState,(KopiLua.Lua.lua_CFunction)o);
} }
else if(o is LuaFunction) else if(o is LuaFunction)
{ {
...@@ -811,7 +811,7 @@ namespace LuaInterface ...@@ -811,7 +811,7 @@ namespace LuaInterface
* Checks if the method matches the arguments in the Lua stack, getting * Checks if the method matches the arguments in the Lua stack, getting
* the arguments if it does. * the arguments if it does.
*/ */
internal bool matchParameters(IntPtr luaState,MethodBase method,ref MethodCache methodCache) internal bool matchParameters(KopiLua.Lua.lua_State luaState,MethodBase method,ref MethodCache methodCache)
{ {
return metaFunctions.matchParameters(luaState,method,ref methodCache); return metaFunctions.matchParameters(luaState,method,ref methodCache);
} }
......
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