Commit 2271a771 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fixed test on iOS (device)

parent bf8c5fe6
Subproject commit 31271cd6f1b77768e6f70b4848e22fbc96b17338 Subproject commit 980e734233b9273426ba853b7078fddbc1f07549
Subproject commit f6a5029fb6650fe1cb763de1adf0df2f76a2fab6 Subproject commit ed5b8b89e20a6e230e12da1059918f6609bde2eb
...@@ -30,7 +30,11 @@ using LuaInterface.Extensions; ...@@ -30,7 +30,11 @@ using LuaInterface.Extensions;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Type checking and conversion functions. * Type checking and conversion functions.
......
...@@ -26,7 +26,11 @@ using System; ...@@ -26,7 +26,11 @@ using System;
namespace LuaInterface.Event namespace LuaInterface.Event
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/// <summary> /// <summary>
/// Event args for hook callback event /// Event args for hook callback event
......
...@@ -44,7 +44,7 @@ namespace LuaInterface.Extensions ...@@ -44,7 +44,7 @@ namespace LuaInterface.Extensions
public static bool IsNull (this IntPtr ptr) public static bool IsNull (this IntPtr ptr)
{ {
return (ptr == null || ptr.Equals (IntPtr.Zero)); return (ptr.Equals (IntPtr.Zero));
} }
} }
} }
\ No newline at end of file
...@@ -26,7 +26,11 @@ using System; ...@@ -26,7 +26,11 @@ using System;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Class used for generating delegates that get a table from the Lua * Class used for generating delegates that get a table from the Lua
* stack as a an object of a specific type. * stack as a an object of a specific type.
......
...@@ -26,7 +26,11 @@ using System; ...@@ -26,7 +26,11 @@ using System;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Class used for generating delegates that get a function from the Lua * Class used for generating delegates that get a function from the Lua
* stack as a delegate of a specific type. * stack as a delegate of a specific type.
......
...@@ -36,7 +36,11 @@ using LuaInterface.Extensions; ...@@ -36,7 +36,11 @@ using LuaInterface.Extensions;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Main class of LuaInterface * Main class of LuaInterface
...@@ -165,6 +169,7 @@ namespace LuaInterface ...@@ -165,6 +169,7 @@ namespace LuaInterface
LuaLib.lua_settable (luaState, -3); LuaLib.lua_settable (luaState, -3);
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals); LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
translator = new ObjectTranslator (this, luaState); translator = new ObjectTranslator (this, luaState);
ObjectTranslatorPool.Instance.Add (luaState, translator);
LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals); LuaLib.lua_replace (luaState, (int)LuaIndexes.Globals);
LuaLib.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
...@@ -200,6 +205,7 @@ namespace LuaInterface ...@@ -200,6 +205,7 @@ namespace LuaInterface
LuaLib.lua_settable (lState, -3); LuaLib.lua_settable (lState, -3);
LuaLib.lua_replace (lState, (int)LuaIndexes.Globals); LuaLib.lua_replace (lState, (int)LuaIndexes.Globals);
translator = new ObjectTranslator (this, luaState); translator = new ObjectTranslator (this, luaState);
ObjectTranslatorPool.Instance.Add (luaState, translator);
LuaLib.lua_replace (lState, (int)LuaIndexes.Globals); LuaLib.lua_replace (lState, (int)LuaIndexes.Globals);
LuaLib.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
} }
...@@ -235,8 +241,10 @@ namespace LuaInterface ...@@ -235,8 +241,10 @@ namespace LuaInterface
return; return;
////// if(luaState != LuaCore.lua_State.Zero) ////// if(luaState != LuaCore.lua_State.Zero)
if (!luaState.IsNull ()) if (!luaState.IsNull ()) {
LuaCore.lua_close (luaState); LuaCore.lua_close (luaState);
ObjectTranslatorPool.Instance.Remove (luaState);
}
//luaState = LuaCore.lua_State.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id = 44593&forum_id = 146 //luaState = LuaCore.lua_State.Zero; <- suggested by Christopher Cebulski http://luaforge.net/forum/forum.php?thread_id = 44593&forum_id = 146
} }
...@@ -733,7 +741,7 @@ namespace LuaInterface ...@@ -733,7 +741,7 @@ namespace LuaInterface
public int SetDebugHook (EventMasks mask, int count) public int SetDebugHook (EventMasks mask, int count)
{ {
if (hookCallback.IsNull ()) { if (hookCallback.IsNull ()) {
hookCallback = new LuaCore.lua_Hook (DebugHookCallback); hookCallback = new LuaCore.lua_Hook (Lua.DebugHookCallback);
return LuaCore.lua_sethook (luaState, hookCallback, (int)mask, count); return LuaCore.lua_sethook (luaState, hookCallback, (int)mask, count);
} }
...@@ -875,7 +883,15 @@ namespace LuaInterface ...@@ -875,7 +883,15 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_Hook))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_Hook))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private void DebugHookCallback (LuaCore.lua_State luaState, LuaCore.lua_Debug luaDebug) private static void DebugHookCallback (LuaCore.lua_State luaState, LuaCore.lua_Debug luaDebug)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
var lua = translator.Interpreter;
lua.DebugHookCallbackInternal (luaState, luaDebug);
}
private void DebugHookCallbackInternal (LuaCore.lua_State luaState, LuaCore.lua_Debug luaDebug)
{ {
try { try {
var temp = DebugHook; var temp = DebugHook;
......
...@@ -28,7 +28,11 @@ using System.Collections.Generic; ...@@ -28,7 +28,11 @@ using System.Collections.Generic;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
public class LuaFunction : LuaBase public class LuaFunction : LuaBase
{ {
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>False</Optimize> <Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath> <OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;MONOTOUCH</DefineConstants> <DefineConstants>DEBUG;MONOTOUCH;</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>
<DefineConstants>MONOTOUCH</DefineConstants> <DefineConstants>MONOTOUCH;</DefineConstants>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
...@@ -91,6 +91,7 @@ ...@@ -91,6 +91,7 @@
<Compile Include="Metatables.cs" /> <Compile Include="Metatables.cs" />
<Compile Include="ObjectTranslator.cs" /> <Compile Include="ObjectTranslator.cs" />
<Compile Include="ProxyType.cs" /> <Compile Include="ProxyType.cs" />
<Compile Include="ObjectTranslatorPool.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\KeraLua\KeraLua.iOS.csproj"> <ProjectReference Include="..\KeraLua\KeraLua.iOS.csproj">
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
<AssemblyName>LuaInterface</AssemblyName> <AssemblyName>LuaInterface</AssemblyName>
<ReleaseVersion>2.x</ReleaseVersion> <ReleaseVersion>2.x</ReleaseVersion>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
...@@ -79,6 +78,7 @@ ...@@ -79,6 +78,7 @@
<Compile Include="LuaLib\GCOptions.cs" /> <Compile Include="LuaLib\GCOptions.cs" />
<Compile Include="LuaLib\LuaLib.cs" /> <Compile Include="LuaLib\LuaLib.cs" />
<Compile Include="Config\LuaInterfaceConfig.cs" /> <Compile Include="Config\LuaInterfaceConfig.cs" />
<Compile Include="ObjectTranslatorPool.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
--> -->
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\KeraLua\KeraLua.csproj"> <ProjectReference Include="..\KeraLua\KeraLua.csproj">
<Project>{47153754-10f5-44d8-b578-f5a32b69061a}</Project> <Project>{47153754-10F5-44D8-B578-F5A32B69061A}</Project>
<Name>KeraLua</Name> <Name>KeraLua</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\KopiLua\KopiLua.csproj"> <ProjectReference Include="..\KopiLua\KopiLua.csproj">
......
...@@ -29,7 +29,11 @@ using LuaInterface.Extensions; ...@@ -29,7 +29,11 @@ using LuaInterface.Extensions;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
public class LuaLib public class LuaLib
{ {
......
...@@ -29,7 +29,11 @@ using System.Collections.Generic; ...@@ -29,7 +29,11 @@ using System.Collections.Generic;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Wrapper class for Lua tables * Wrapper class for Lua tables
......
...@@ -28,7 +28,11 @@ using System.Collections.Generic; ...@@ -28,7 +28,11 @@ using System.Collections.Generic;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
public class LuaUserData : LuaBase public class LuaUserData : LuaBase
{ {
......
...@@ -34,7 +34,11 @@ using LuaInterface.Extensions; ...@@ -34,7 +34,11 @@ using LuaInterface.Extensions;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Functions used in the metatables of userdata representing * Functions used in the metatables of userdata representing
...@@ -43,7 +47,7 @@ namespace LuaInterface ...@@ -43,7 +47,7 @@ namespace LuaInterface
* Author: Fabio Mascarenhas * Author: Fabio Mascarenhas
* Version: 1.0 * Version: 1.0
*/ */
class MetaFunctions public class MetaFunctions
{ {
internal LuaCore.lua_CFunction gcFunction, indexFunction, newindexFunction, baseIndexFunction, internal LuaCore.lua_CFunction gcFunction, indexFunction, newindexFunction, baseIndexFunction,
classIndexFunction, classNewindexFunction, execDelegateFunction, callConstructorFunction, toStringFunction; classIndexFunction, classNewindexFunction, execDelegateFunction, callConstructorFunction, toStringFunction;
...@@ -72,15 +76,15 @@ namespace LuaInterface ...@@ -72,15 +76,15 @@ namespace LuaInterface
public MetaFunctions (ObjectTranslator translator) public MetaFunctions (ObjectTranslator translator)
{ {
this.translator = translator; this.translator = translator;
gcFunction = new LuaCore.lua_CFunction (this.collectObject); gcFunction = new LuaCore.lua_CFunction (MetaFunctions.collectObject);
toStringFunction = new LuaCore.lua_CFunction (this.toString); toStringFunction = new LuaCore.lua_CFunction (MetaFunctions.toString);
indexFunction = new LuaCore.lua_CFunction (this.getMethod); indexFunction = new LuaCore.lua_CFunction (MetaFunctions.getMethod);
newindexFunction = new LuaCore.lua_CFunction (this.setFieldOrProperty); newindexFunction = new LuaCore.lua_CFunction (MetaFunctions.setFieldOrProperty);
baseIndexFunction = new LuaCore.lua_CFunction (this.getBaseMethod); baseIndexFunction = new LuaCore.lua_CFunction (MetaFunctions.getBaseMethod);
callConstructorFunction = new LuaCore.lua_CFunction (this.callConstructor); callConstructorFunction = new LuaCore.lua_CFunction (MetaFunctions.callConstructor);
classIndexFunction = new LuaCore.lua_CFunction (this.getClassMethod); classIndexFunction = new LuaCore.lua_CFunction (MetaFunctions.getClassMethod);
classNewindexFunction = new LuaCore.lua_CFunction (this.setClassFieldOrProperty); classNewindexFunction = new LuaCore.lua_CFunction (MetaFunctions.setClassFieldOrProperty);
execDelegateFunction = new LuaCore.lua_CFunction (this.runFunctionDelegate); execDelegateFunction = new LuaCore.lua_CFunction (MetaFunctions.runFunctionDelegate);
} }
/* /*
...@@ -90,7 +94,13 @@ namespace LuaInterface ...@@ -90,7 +94,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int runFunctionDelegate (LuaCore.lua_State luaState) private static int runFunctionDelegate (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return runFunctionDelegate (luaState, translator);
}
private static int runFunctionDelegate (LuaCore.lua_State luaState, ObjectTranslator translator)
{ {
LuaCore.lua_CFunction func = (LuaCore.lua_CFunction)translator.getRawNetObject (luaState, 1); LuaCore.lua_CFunction func = (LuaCore.lua_CFunction)translator.getRawNetObject (luaState, 1);
LuaLib.lua_remove (luaState, 1); LuaLib.lua_remove (luaState, 1);
...@@ -104,15 +114,18 @@ namespace LuaInterface ...@@ -104,15 +114,18 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int collectObject (LuaCore.lua_State luaState) private static int collectObject (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return collectObject (luaState, translator);
}
private static int collectObject (LuaCore.lua_State luaState, ObjectTranslator translator)
{ {
int udata = LuaLib.luanet_rawnetobj (luaState, 1); int udata = LuaLib.luanet_rawnetobj (luaState, 1);
if (udata != -1) if (udata != -1)
translator.collectObject (udata); translator.collectObject (udata);
else {
// Debug.WriteLine("not found: " + udata);
}
return 0; return 0;
} }
...@@ -124,7 +137,13 @@ namespace LuaInterface ...@@ -124,7 +137,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int toString (LuaCore.lua_State luaState) private static int toString (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return toString (luaState, translator);
}
private static int toString (LuaCore.lua_State luaState, ObjectTranslator translator)
{ {
object obj = translator.getRawNetObject (luaState, 1); object obj = translator.getRawNetObject (luaState, 1);
...@@ -172,7 +191,14 @@ namespace LuaInterface ...@@ -172,7 +191,14 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int getMethod (LuaCore.lua_State luaState) private static int getMethod (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
var instance = translator.MetaFunctionsInstance;
return instance.getMethodInternal (luaState);
}
private int getMethodInternal (LuaCore.lua_State luaState)
{ {
object obj = translator.getRawNetObject (luaState, 1); object obj = translator.getRawNetObject (luaState, 1);
...@@ -267,7 +293,14 @@ namespace LuaInterface ...@@ -267,7 +293,14 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int getBaseMethod (LuaCore.lua_State luaState) private static int getBaseMethod (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
var instance = translator.MetaFunctionsInstance;
return instance.getBaseMethodInternal (luaState);
}
private int getBaseMethodInternal (LuaCore.lua_State luaState)
{ {
object obj = translator.getRawNetObject (luaState, 1); object obj = translator.getRawNetObject (luaState, 1);
...@@ -468,7 +501,14 @@ namespace LuaInterface ...@@ -468,7 +501,14 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int setFieldOrProperty (LuaCore.lua_State luaState) private static int setFieldOrProperty (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
var instance = translator.MetaFunctionsInstance;
return instance.setFieldOrPropertyInternal (luaState);
}
private int setFieldOrPropertyInternal (LuaCore.lua_State luaState)
{ {
object target = translator.getRawNetObject (luaState, 1); object target = translator.getRawNetObject (luaState, 1);
...@@ -635,7 +675,14 @@ namespace LuaInterface ...@@ -635,7 +675,14 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int getClassMethod (LuaCore.lua_State luaState) private static int getClassMethod (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
var instance = translator.MetaFunctionsInstance;
return instance.getClassMethodInternal (luaState);
}
private int getClassMethodInternal (LuaCore.lua_State luaState)
{ {
IReflect klass; IReflect klass;
object obj = translator.getRawNetObject (luaState, 1); object obj = translator.getRawNetObject (luaState, 1);
...@@ -670,7 +717,14 @@ namespace LuaInterface ...@@ -670,7 +717,14 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int setClassFieldOrProperty (LuaCore.lua_State luaState) private static int setClassFieldOrProperty (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
var instance = translator.MetaFunctionsInstance;
return instance.setClassFieldOrPropertyInternal (luaState);
}
private int setClassFieldOrPropertyInternal (LuaCore.lua_State luaState)
{ {
IReflect target; IReflect target;
object obj = translator.getRawNetObject (luaState, 1); object obj = translator.getRawNetObject (luaState, 1);
...@@ -694,7 +748,14 @@ namespace LuaInterface ...@@ -694,7 +748,14 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int callConstructor (LuaCore.lua_State luaState) private static int callConstructor (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
var instance = translator.MetaFunctionsInstance;
return instance.callConstructorInternal (luaState);
}
private int callConstructorInternal (LuaCore.lua_State luaState)
{ {
var validConstructor = new MethodCache (); var validConstructor = new MethodCache ();
IReflect klass; IReflect klass;
......
...@@ -30,7 +30,11 @@ using LuaInterface.Extensions; ...@@ -30,7 +30,11 @@ using LuaInterface.Extensions;
namespace LuaInterface.Method namespace LuaInterface.Method
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Argument extraction with type-conversion function * Argument extraction with type-conversion function
...@@ -108,10 +112,6 @@ namespace LuaInterface.Method ...@@ -108,10 +112,6 @@ namespace LuaInterface.Method
* 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.
*/ */
#if MONOTOUCH
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls]
int call (LuaCore.lua_State luaState) int call (LuaCore.lua_State luaState)
{ {
var methodToCall = _Method; var methodToCall = _Method;
......
...@@ -34,7 +34,11 @@ using LuaInterface.Extensions; ...@@ -34,7 +34,11 @@ using LuaInterface.Extensions;
namespace LuaInterface namespace LuaInterface
{ {
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua; using LuaCore = KeraLua.Lua;
#endif
/* /*
* Passes objects from the CLR to Lua and vice-versa * Passes objects from the CLR to Lua and vice-versa
...@@ -60,6 +64,18 @@ namespace LuaInterface ...@@ -60,6 +64,18 @@ namespace LuaInterface
/// </summary> /// </summary>
private int nextObj = 0; private int nextObj = 0;
public MetaFunctions MetaFunctionsInstance {
get {
return metaFunctions;
}
}
public Lua Interpreter {
get {
return interpreter;
}
}
public ObjectTranslator (Lua interpreter, LuaCore.lua_State luaState) public ObjectTranslator (Lua interpreter, LuaCore.lua_State luaState)
{ {
this.interpreter = interpreter; this.interpreter = interpreter;
...@@ -67,12 +83,12 @@ namespace LuaInterface ...@@ -67,12 +83,12 @@ namespace LuaInterface
metaFunctions = new MetaFunctions (this); metaFunctions = new MetaFunctions (this);
assemblies = new List<Assembly> (); assemblies = new List<Assembly> ();
importTypeFunction = new LuaCore.lua_CFunction (this.importType); importTypeFunction = new LuaCore.lua_CFunction (ObjectTranslator.importType);
loadAssemblyFunction = new LuaCore.lua_CFunction (this.loadAssembly); loadAssemblyFunction = new LuaCore.lua_CFunction (ObjectTranslator.loadAssembly);
registerTableFunction = new LuaCore.lua_CFunction (this.registerTable); registerTableFunction = new LuaCore.lua_CFunction (ObjectTranslator.registerTable);
unregisterTableFunction = new LuaCore.lua_CFunction (this.unregisterTable); unregisterTableFunction = new LuaCore.lua_CFunction (ObjectTranslator.unregisterTable);
getMethodSigFunction = new LuaCore.lua_CFunction (this.getMethodSignature); getMethodSigFunction = new LuaCore.lua_CFunction (ObjectTranslator.getMethodSignature);
getConstructorSigFunction = new LuaCore.lua_CFunction (this.getConstructorSignature); getConstructorSigFunction = new LuaCore.lua_CFunction (ObjectTranslator.getConstructorSignature);
createLuaObjectList (luaState); createLuaObjectList (luaState);
createIndexingMetaFunction (luaState); createIndexingMetaFunction (luaState);
...@@ -236,7 +252,13 @@ namespace LuaInterface ...@@ -236,7 +252,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int loadAssembly (LuaCore.lua_State luaState) private static int loadAssembly (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return translator.loadAssemblyInternal (luaState);
}
private int loadAssemblyInternal (LuaCore.lua_State luaState)
{ {
try { try {
string assemblyName = LuaLib.lua_tostring (luaState, 1).ToString (); string assemblyName = LuaLib.lua_tostring (luaState, 1).ToString ();
...@@ -279,7 +301,13 @@ namespace LuaInterface ...@@ -279,7 +301,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int importType (LuaCore.lua_State luaState) private static int importType (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return translator.importTypeInternal (luaState);
}
private int importTypeInternal (LuaCore.lua_State luaState)
{ {
string className = LuaLib.lua_tostring (luaState, 1).ToString (); string className = LuaLib.lua_tostring (luaState, 1).ToString ();
var klass = FindType (className); var klass = FindType (className);
...@@ -301,7 +329,13 @@ namespace LuaInterface ...@@ -301,7 +329,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int registerTable (LuaCore.lua_State luaState) private static int registerTable (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return translator.registerTableInternal (luaState);
}
private int registerTableInternal (LuaCore.lua_State luaState)
{ {
if (LuaLib.lua_type (luaState, 1) == LuaTypes.Table) { if (LuaLib.lua_type (luaState, 1) == LuaTypes.Table) {
var luaTable = getTable (luaState, 1); var luaTable = getTable (luaState, 1);
...@@ -347,7 +381,13 @@ namespace LuaInterface ...@@ -347,7 +381,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int unregisterTable (LuaCore.lua_State luaState) private static int unregisterTable (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return translator.unregisterTableInternal (luaState);
}
private int unregisterTableInternal (LuaCore.lua_State luaState)
{ {
try { try {
if (LuaLib.lua_getmetatable (luaState, 1) != 0) { if (LuaLib.lua_getmetatable (luaState, 1) != 0) {
...@@ -386,7 +426,13 @@ namespace LuaInterface ...@@ -386,7 +426,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int getMethodSignature (LuaCore.lua_State luaState) private static int getMethodSignature (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return translator.getMethodSignatureInternal (luaState);
}
private int getMethodSignatureInternal (LuaCore.lua_State luaState)
{ {
IReflect klass; IReflect klass;
object target; object target;
...@@ -434,7 +480,13 @@ namespace LuaInterface ...@@ -434,7 +480,13 @@ namespace LuaInterface
[MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))] [MonoTouch.MonoPInvokeCallback (typeof (LuaCore.lua_CFunction))]
#endif #endif
[System.Runtime.InteropServices.AllowReversePInvokeCalls] [System.Runtime.InteropServices.AllowReversePInvokeCalls]
private int getConstructorSignature (LuaCore.lua_State luaState) private static int getConstructorSignature (LuaCore.lua_State luaState)
{
var translator = ObjectTranslatorPool.Instance.Find (luaState);
return translator.getConstructorSignatureInternal (luaState);
}
private int getConstructorSignatureInternal (LuaCore.lua_State luaState)
{ {
IReflect klass = null; IReflect klass = null;
int udata = LuaLib.luanet_checkudata (luaState, 1, "luaNet_class"); int udata = LuaLib.luanet_checkudata (luaState, 1, "luaNet_class");
......
using System;
using System.Collections.Generic;
namespace LuaInterface
{
#if USE_KOPILUA
using LuaCore = KopiLua.Lua;
#else
using LuaCore = KeraLua.Lua;
#endif
internal class ObjectTranslatorPool
{
private static volatile ObjectTranslatorPool instance = new ObjectTranslatorPool ();
private static object syncRoot = new object ();
private Dictionary<LuaCore.lua_State, ObjectTranslator> translators = new Dictionary<LuaCore.lua_State, ObjectTranslator>();
public static ObjectTranslatorPool Instance
{
get
{
return instance;
}
}
public ObjectTranslatorPool ()
{
syncRoot = new Dictionary<LuaCore.lua_State, ObjectTranslator> ();
}
public void Add (LuaCore.lua_State luaState, ObjectTranslator translator)
{
translators.Add(luaState , translator);
}
public ObjectTranslator Find (LuaCore.lua_State luaState)
{
if (!translators.ContainsKey(luaState))
return null;
return translators [luaState];
}
public void Remove (LuaCore.lua_State luaState)
{
if (!translators.ContainsKey (luaState))
return;
translators.Remove (luaState);
}
}
}
...@@ -64,7 +64,9 @@ ...@@ -64,7 +64,9 @@
<IpaPackageName /> <IpaPackageName />
<MtouchI18n /> <MtouchI18n />
<MtouchArch>ARMv7</MtouchArch> <MtouchArch>ARMv7</MtouchArch>
<MtouchLink>Full</MtouchLink> <MtouchLink>None</MtouchLink>
<MtouchUseLlvm>true</MtouchUseLlvm>
<MtouchUseThumb>true</MtouchUseThumb>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Ad-Hoc|iPhone' ">
<DebugType>none</DebugType> <DebugType>none</DebugType>
......
...@@ -348,6 +348,16 @@ namespace LuaInterfaceTest ...@@ -348,6 +348,16 @@ namespace LuaInterfaceTest
//lua.RegisterFunction("regularMethod", genericClass, typeof(TestClassGeneric<>).GetMethod("RegularMethod")); //lua.RegisterFunction("regularMethod", genericClass, typeof(TestClassGeneric<>).GetMethod("RegularMethod"));
using (Lua lua = new Lua ()) { using (Lua lua = new Lua ()) {
TestClassWithGenericMethod classWithGenericMethod = new TestClassWithGenericMethod (); TestClassWithGenericMethod classWithGenericMethod = new TestClassWithGenericMethod ();
////////////////////////////////////////////////////////////////////////////
/// ////////////////////////////////////////////////////////////////////////
/// IMPORTANT: Use generic method with the type you will call or generic methods will fail with iOS
/// ////////////////////////////////////////////////////////////////////////
classWithGenericMethod.GenericMethod<double>(99.0);
classWithGenericMethod.GenericMethod<TestClass>(new TestClass (99));
////////////////////////////////////////////////////////////////////////////
/// ////////////////////////////////////////////////////////////////////////
lua.RegisterFunction ("genericMethod2", classWithGenericMethod, typeof(TestClassWithGenericMethod).GetMethod ("GenericMethod")); lua.RegisterFunction ("genericMethod2", classWithGenericMethod, typeof(TestClassWithGenericMethod).GetMethod ("GenericMethod"));
try { try {
......
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