Commit b5b573a3 authored by Megax's avatar Megax
Browse files

* lua_Debug osztaly a KopiLua-bol lesz ezentul meghivva. Igy tokeletesen fog...

* lua_Debug osztaly a KopiLua-bol lesz ezentul meghivva. Igy tokeletesen fog mukodni a konvertalas es a meghivas. Ket fv atalakitasa visszamaradt.
parent b969a882
using System; using System;
using LuaInterface;
using System.Threading; using System.Threading;
using LuaInterface;
/* /*
* Application to run Lua scripts that can use LuaInterface * Application to run Lua scripts that can use LuaInterface
......
...@@ -639,7 +639,7 @@ namespace KopiLua ...@@ -639,7 +639,7 @@ namespace KopiLua
lua_pushvalue(L, -1); lua_pushvalue(L, -1);
lua_replace(L, LUA_ENVIRONINDEX); lua_replace(L, LUA_ENVIRONINDEX);
/* create `loaders' table */ /* create `loaders' table */
lua_createtable(L, 0, loaders.Length - 1); lua_createtable(L, loaders.Length - 1, 0);
/* fill it with pre-defined loaders */ /* fill it with pre-defined loaders */
for (i=0; loaders[i] != null; i++) { for (i=0; loaders[i] != null; i++) {
lua_pushcfunction(L, loaders[i]); lua_pushcfunction(L, loaders[i]);
......
...@@ -27,20 +27,22 @@ using System; ...@@ -27,20 +27,22 @@ using System;
namespace LuaInterface.Event namespace LuaInterface.Event
{ {
using LuaCore = KopiLua.Lua;
/// <summary> /// <summary>
/// Event args for hook callback event /// Event args for hook callback event
/// </summary> /// </summary>
/// <author>Reinhard Ostermeier</author> /// <author>Reinhard Ostermeier</author>
public class DebugHookEventArgs : EventArgs public class DebugHookEventArgs : EventArgs
{ {
private readonly LuaDebug luaDebug; private readonly LuaCore.lua_Debug luaDebug;
public DebugHookEventArgs(LuaDebug luaDebug) public DebugHookEventArgs(LuaCore.lua_Debug luaDebug)
{ {
this.luaDebug = luaDebug; this.luaDebug = luaDebug;
} }
public LuaDebug LuaDebug public LuaCore.lua_Debug LuaDebug
{ {
get { return luaDebug; } get { return luaDebug; }
} }
......
/*
* This file is part of LuaInterface.
*
* Copyright (C) 2003-2005 Fabio Mascarenhas de Queiroz.
* Copyright (C) 2012 Megax <http://megax.yeahunter.hu/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System;
namespace LuaInterface.Event
{
/// <summary>
/// Structure for lua debug information
/// </summary>
/// <remarks>
/// Do not change this struct because it must match the lua structure lua_debug
/// </remarks>
/// <author>Reinhard Ostermeier</author>
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct LuaDebug
{
public EventCodes eventCode;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public string name;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public string namewhat;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public string what;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPStr)]
public string source;
public int currentline;
public int nups;
public int linedefined;
public int lastlinedefined;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 60/*LUA_IDSIZE*/)]
public string shortsrc;
public int i_ci;
}
}
\ No newline at end of file
...@@ -758,10 +758,9 @@ namespace LuaInterface ...@@ -758,10 +758,9 @@ namespace LuaInterface
} }
/* /*
* Lets go of a previously allocated reference to a table, function * Lets go of a previously allocated reference to a table, function
* or userdata * or userdata
*/ */
#region lua debug functions #region lua debug functions
/// <summary> /// <summary>
/// Activates the debug hook /// Activates the debug hook
...@@ -770,15 +769,16 @@ namespace LuaInterface ...@@ -770,15 +769,16 @@ 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.IsNull()) if(hookCallback.IsNull())
{ {
hookCallback = new LuaCore.lua_Hook(DebugHookCallback); hookCallback = new LuaCore.lua_Hook(DebugHookCallback);
return LuaCore.lua_sethook(luaState, hookCallback, (int)mask, count); return LuaCore.lua_sethook(luaState, hookCallback, (int)mask, count);
} }
return -1; return -1;
}*/ }
/// <summary> /// <summary>
/// Removes the debug hook /// Removes the debug hook
...@@ -818,19 +818,19 @@ namespace LuaInterface ...@@ -818,19 +818,19 @@ 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 LuaCore.lua_Debug luaDebug)
{ {
luaDebug = new LuaDebug(); luaDebug = new LuaDebug();
LuaCore.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug)); LuaCore.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 LuaCore.lua_getstack(luaState, level, ld) != 0; return LuaCore.lua_getstack(luaState, level, luaDebug) != 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);
} }
}*/ }*/
...@@ -841,18 +841,18 @@ namespace LuaInterface ...@@ -841,18 +841,18 @@ 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 LuaCore.lua_Debug luaDebug)
{ {
LuaCore.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug)); LuaCore.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 LuaCore.lua_getinfo(luaState, what, ld); return LuaCore.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);
} }
}*/ }*/
...@@ -863,19 +863,17 @@ namespace LuaInterface ...@@ -863,19 +863,17 @@ 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(LuaCore.lua_Debug luaDebug, int n)
{ {
LuaCore.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try try
{ {
return LuaCore.lua_getlocal(luaState, ld, n); return LuaCore.lua_getlocal(luaState, luaDebug, n).ToString();
} }
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)
...@@ -884,19 +882,17 @@ namespace LuaInterface ...@@ -884,19 +882,17 @@ 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(LuaCore.lua_Debug luaDebug, int n)
{ {
LuaCore.lua_State ld = System.Runtime.InteropServices.Marshal.AllocHGlobal(System.Runtime.InteropServices.Marshal.SizeOf(luaDebug));
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try try
{ {
return LuaCore.lua_setlocal(luaState, ld, n); return LuaCore.lua_setlocal(luaState, luaDebug, n).ToString();
} }
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)
...@@ -928,22 +924,20 @@ namespace LuaInterface ...@@ -928,22 +924,20 @@ 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(LuaCore.lua_State luaState, LuaCore.lua_Debug luaDebug) private void DebugHookCallback(LuaCore.lua_State luaState, LuaCore.lua_Debug luaDebug)
{ {
try try
{ {
LuaDebug ld = (LuaDebug)System.Runtime.InteropServices.Marshal.PtrToStructure(luaDebug, typeof(LuaDebug)); var temp = DebugHook;
EventHandler<DebugHookEventArgs> temp = DebugHook;
if(temp != null) if(!temp.IsNull())
{ temp(this, new DebugHookEventArgs(luaDebug));
temp(this, new DebugHookEventArgs(ld));
}
} }
catch (Exception ex) catch(Exception ex)
{ {
OnHookException(new HookExceptionEventArgs(ex)); OnHookException(new HookExceptionEventArgs(ex));
} }
}*/ }
private void OnHookException(HookExceptionEventArgs e) private void OnHookException(HookExceptionEventArgs e)
{ {
......
...@@ -78,7 +78,6 @@ ...@@ -78,7 +78,6 @@
<Compile Include="GenerateEventAssembly\CodeGeneration.cs" /> <Compile Include="GenerateEventAssembly\CodeGeneration.cs" />
<Compile Include="Event\EventCodes.cs" /> <Compile Include="Event\EventCodes.cs" />
<Compile Include="Event\EventMasks.cs" /> <Compile Include="Event\EventMasks.cs" />
<Compile Include="Event\LuaDebug.cs" />
<Compile Include="Event\DebugHookEventArgs.cs" /> <Compile Include="Event\DebugHookEventArgs.cs" />
<Compile Include="Event\HookExceptionEventArgs.cs" /> <Compile Include="Event\HookExceptionEventArgs.cs" />
<Compile Include="Exceptions\LuaException.cs" /> <Compile Include="Exceptions\LuaException.cs" />
......
...@@ -38,22 +38,6 @@ namespace LuaInterface ...@@ -38,22 +38,6 @@ namespace LuaInterface
{ {
private static int tag = 0; private static int tag = 0;
/// <summary>
/// Function to get byte array from a object
/// </summary>
/// <param name="_Object">object to get byte array</param>
/// <returns>Byte Array</returns>
public static byte[] ObjectToByteArray(object obj)
{
if(obj.IsNull())
return null;
var bf = new BinaryFormatter();
var ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
public static LuaTypes ToLuaTypes(this int type) public static LuaTypes ToLuaTypes(this int type)
{ {
return (LuaTypes)type; return (LuaTypes)type;
...@@ -171,7 +155,7 @@ namespace LuaInterface ...@@ -171,7 +155,7 @@ namespace LuaInterface
public static int checkudata_raw(LuaCore.lua_State luaState, int ud, string tname) public static int checkudata_raw(LuaCore.lua_State luaState, int ud, string tname)
{ {
int p = (int)LuaCore.lua_touserdata2(luaState, ud); int p = (int)LuaCore.lua_touserdata2(luaState, ud);
//Console.WriteLine(BitConverter.ToInt32(ObjectToByteArray(LuaCore.lua_touserdata(luaState, ud)), 0));
if(p != 0) if(p != 0)
{ {
/* value is a userdata? */ /* value is a userdata? */
......
...@@ -172,7 +172,7 @@ namespace LuaInterface ...@@ -172,7 +172,7 @@ namespace LuaInterface
} }
object index = translator.getObject(luaState, 2); object index = translator.getObject(luaState, 2);
var indexType = index.GetType(); //var indexType = index.GetType();
string methodName = index as string; // will be null if not a string arg string methodName = index as string; // will be null if not a string arg
var objType = obj.GetType(); var objType = obj.GetType();
......
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