Unverified Commit 1cc74393 authored by Vinicius Jarina's avatar Vinicius Jarina Committed by GitHub
Browse files

* Giant cleanup/reshuffle of all files. (#265)

* * Giant cleanup/reshuffle of all files.

* * Update upstream `KeraLua` to `0.1.14`

* Fixed .NET Core build.

* Add runsettings file

* * Fixed nuspec `dependencies` node

* Ignore _ in branch names for package names.

* * Fixed nuspec.
parent 3f254585
erase tests\*.dll
msbuild NLua.Net35.sln /p:Configuration=ReleaseKopiLua /p:Platform="Any CPU"
cd tests/
nunit-console NLuaTest.dll /xml=$1
cd ..
\ No newline at end of file
erase tests\*.dll
msbuild NLua.Net40.sln /p:Configuration=ReleaseKopiLua /p:Platform="Any CPU"
cd tests/
nunit-console NLuaTest.dll /xml=$1
cd ..
\ No newline at end of file
erase tests\*.dll
msbuild NLua.Net45.sln /p:Configuration=ReleaseKopiLua /p:Platform="Any CPU"
cd tests/
nunit-console NLuaTest.dll /xml=$1
cd ..
\ No newline at end of file
erase tests\*.dll
cd Core\KeraLua
call Makefile.Win32.bat
msbuild KeraLua.Net35.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING" /p:Platform="Any CPU"
cd ..\..
xcopy Core\KeraLua\external\lua\win32\bin\*.dll tests\*.dll
msbuild NLua.Net35.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING;LUA_CORE;CATCH_EXCEPTIONS;NET_3_5" /p:Platform="Any CPU"
cd tests/
nunit-console-x86 NLuaTest.dll /xml=$1
cd ..
erase tests\*.dll
cd Core\KeraLua
call Makefile.Win32.bat
msbuild KeraLua.Net40.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING" /p:Platform="Any CPU"
cd ..\..
xcopy Core\KeraLua\external\lua\win32\bin\*.dll tests\*.dll
msbuild NLua.Net40.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING;LUA_CORE;CATCH_EXCEPTIONS" /p:Platform="Any CPU"
cd tests/
nunit-console-x86 NLuaTest.dll /xml=$1
cd ..
erase tests\*.dll
cd Core\KeraLua
call Makefile.Win32.bat
msbuild KeraLua.Net45.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING" /p:Platform="Any CPU"
cd ..\..
xcopy Core\KeraLua\external\lua\win32\bin\*.dll tests\*.dll
msbuild NLua.Net45.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING;LUA_CORE;CATCH_EXCEPTIONS" /p:Platform="Any CPU"
cd tests/
nunit-console-x86 NLuaTest.dll /xml=$1
cd ..
erase tests\*.dll
cd Core\KeraLua
call Makefile.Win64.bat
msbuild KeraLua.Net35.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING" /p:Platform="Any CPU"
cd ..\..
xcopy Core\KeraLua\external\lua\win64\bin64\*.dll tests\*.dll
msbuild NLua.Net35.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING;LUA_CORE;CATCH_EXCEPTIONS;NET_3_5" /p:Platform="Any CPU"
cd tests/
nunit-console NLuaTest.dll /xml=$1
cd ..
erase tests\*.dll
cd Core\KeraLua
call Makefile.Win64.bat
msbuild KeraLua.Net40.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING" /p:Platform="Any CPU"
cd ..\..
xcopy Core\KeraLua\external\lua\win64\bin64\*.dll tests\*.dll
msbuild NLua.Net40.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING;LUA_CORE;CATCH_EXCEPTIONS" /p:Platform="Any CPU"
cd tests/
nunit-console NLuaTest.dll /xml=$1
cd ..
erase tests\*.dll
cd Core\KeraLua
call Makefile.Win64.bat
msbuild KeraLua.Net45.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING" /p:Platform="Any CPU"
cd ..\..
xcopy Core\KeraLua\external\lua\win64\bin64\*.dll tests\*.dll
msbuild NLua.Net45.sln /p:Configuration=Release /p:DefineConstants="USE_DYNAMIC_DLL_REGISTER;WSTRING;LUA_CORE;CATCH_EXCEPTIONS" /p:Platform="Any CPU"
cd tests/
nunit-console NLuaTest.dll /xml=$1
cd ..
msbuild NLua.WP8.sln /p:Configuration=Release /p:Platform="ARM"
msbuild NLua.WP8.sln /p:Configuration=Release /p:Platform="Win32"
msbuild NLua.WPSL8.sln /p:Configuration=Release /p:Platform="ARM"
msbuild NLua.WPSL8.sln /p:Configuration=Release /p:Platform="Win32"
using System;
using System.Collections.Generic;
using KeraLua;
using NLua.Method;
using NLua.Extensions;
namespace NLua
{
using LuaState = KeraLua.Lua;
sealed class CheckType
{
Dictionary<Type, ExtractValue> extractValues = new Dictionary<Type, ExtractValue>();
ExtractValue extractNetObject;
ObjectTranslator translator;
public CheckType(ObjectTranslator translator)
{
this.translator = translator;
extractValues.Add(GetExtractDictionaryKey(typeof(object)), new ExtractValue(GetAsObject));
extractValues.Add(GetExtractDictionaryKey(typeof(sbyte)), new ExtractValue(GetAsSbyte));
extractValues.Add(GetExtractDictionaryKey(typeof(byte)), new ExtractValue(GetAsByte));
extractValues.Add(GetExtractDictionaryKey(typeof(short)), new ExtractValue(GetAsShort));
extractValues.Add(GetExtractDictionaryKey(typeof(ushort)), new ExtractValue(GetAsUshort));
extractValues.Add(GetExtractDictionaryKey(typeof(int)), new ExtractValue(GetAsInt));
extractValues.Add(GetExtractDictionaryKey(typeof(uint)), new ExtractValue(GetAsUint));
extractValues.Add(GetExtractDictionaryKey(typeof(long)), new ExtractValue(GetAsLong));
extractValues.Add(GetExtractDictionaryKey(typeof(ulong)), new ExtractValue(GetAsUlong));
extractValues.Add(GetExtractDictionaryKey(typeof(double)), new ExtractValue(GetAsDouble));
extractValues.Add(GetExtractDictionaryKey(typeof(char)), new ExtractValue(GetAsChar));
extractValues.Add(GetExtractDictionaryKey(typeof(float)), new ExtractValue(GetAsFloat));
extractValues.Add(GetExtractDictionaryKey(typeof(decimal)), new ExtractValue(GetAsDecimal));
extractValues.Add(GetExtractDictionaryKey(typeof(bool)), new ExtractValue(GetAsBoolean));
extractValues.Add(GetExtractDictionaryKey(typeof(string)), new ExtractValue(GetAsString));
extractValues.Add(GetExtractDictionaryKey(typeof(char[])), new ExtractValue(GetAsCharArray));
extractValues.Add(GetExtractDictionaryKey(typeof(LuaFunction)), new ExtractValue(GetAsFunction));
extractValues.Add(GetExtractDictionaryKey(typeof(LuaTable)), new ExtractValue(GetAsTable));
extractValues.Add(GetExtractDictionaryKey(typeof(LuaUserData)), new ExtractValue(GetAsUserdata));
extractNetObject = new ExtractValue(GetAsNetObject);
}
/*
* Checks if the value at Lua stack index stackPos matches paramType,
* returning a conversion function if it does and null otherwise.
*/
internal ExtractValue GetExtractor(ProxyType paramType)
{
return GetExtractor(paramType.UnderlyingSystemType);
}
internal ExtractValue GetExtractor(Type paramType)
{
if (paramType.IsByRef)
paramType = paramType.GetElementType();
var extractKey = GetExtractDictionaryKey(paramType);
return extractValues.ContainsKey(extractKey) ? extractValues[extractKey] : extractNetObject;
}
internal ExtractValue CheckLuaType(LuaState luaState, int stackPos, Type paramType)
{
LuaType luatype = luaState.Type(stackPos);
if (paramType.IsByRef)
paramType = paramType.GetElementType();
var underlyingType = Nullable.GetUnderlyingType(paramType);
if (underlyingType != null)
{
paramType = underlyingType; // Silently convert nullable types to their non null requics
}
var extractKey = GetExtractDictionaryKey(paramType);
bool netParamIsNumeric = paramType == typeof(int) ||
paramType == typeof(uint) ||
paramType == typeof(long) ||
paramType == typeof(ulong) ||
paramType == typeof(short) ||
paramType == typeof(ushort) ||
paramType == typeof(float) ||
paramType == typeof(double) ||
paramType == typeof(decimal) ||
paramType == typeof(byte);
// If it is a nullable
if (underlyingType != null)
{
// null can always be assigned to nullable
if (luatype == LuaType.Nil)
{
// Return the correct extractor anyways
if (netParamIsNumeric || paramType == typeof(bool))
return extractValues[extractKey];
return extractNetObject;
}
}
if (paramType.Equals(typeof(object)))
return extractValues[extractKey];
//CP: Added support for generic parameters
if (paramType.IsGenericParameter)
{
if (luatype == LuaType.Boolean)
return extractValues[GetExtractDictionaryKey(typeof(bool))];
else if (luatype == LuaType.String)
return extractValues[GetExtractDictionaryKey(typeof(string))];
else if (luatype == LuaType.Table)
return extractValues[GetExtractDictionaryKey(typeof(LuaTable))];
else if (luatype == LuaType.UserData)
return extractValues[GetExtractDictionaryKey(typeof(object))];
else if (luatype == LuaType.Function)
return extractValues[GetExtractDictionaryKey(typeof(LuaFunction))];
else if (luatype == LuaType.Number)
return extractValues[GetExtractDictionaryKey(typeof(double))];
}
bool netParamIsString = paramType == typeof(string) || paramType == typeof(char[]);
if (netParamIsNumeric)
{
if (luaState.IsNumber(stackPos) && !netParamIsString)
return extractValues[extractKey];
}
else if (paramType == typeof(bool))
{
if (luaState.IsBoolean(stackPos))
return extractValues[extractKey];
}
else if (netParamIsString)
{
if (luaState.IsString(stackPos))
return extractValues[extractKey];
else if (luatype == LuaType.Nil)
return extractNetObject; // kevinh - silently convert nil to a null string pointer
}
else if (paramType == typeof(LuaTable))
{
if (luatype == LuaType.Table || luatype == LuaType.Nil)
return extractValues[extractKey];
}
else if (paramType == typeof(LuaUserData))
{
if (luatype == LuaType.UserData || luatype == LuaType.Nil)
return extractValues[extractKey];
}
else if (paramType == typeof(LuaFunction))
{
if (luatype == LuaType.Function || luatype == LuaType.Nil)
return extractValues[extractKey];
}
else if (typeof(Delegate).IsAssignableFrom(paramType) && luatype == LuaType.Function)
return new ExtractValue(new DelegateGenerator(translator, paramType).ExtractGenerated);
else if (paramType.IsInterface && luatype == LuaType.Table)
return new ExtractValue(new ClassGenerator(translator, paramType).ExtractGenerated);
else if ((paramType.IsInterface || paramType.IsClass) && luatype == LuaType.Nil)
{
// kevinh - allow nil to be silently converted to null - extractNetObject will return null when the item ain't found
return extractNetObject;
}
else if (luaState.Type(stackPos) == LuaType.Table)
{
if (luaState.GetMetaField(stackPos, "__index") != LuaType.Nil)
{
object obj = translator.GetNetObject(luaState, -1);
luaState.SetTop(-2);
if (obj != null && paramType.IsAssignableFrom(obj.GetType()))
return extractNetObject;
}
else
return null;
}
else
{
object obj = translator.GetNetObject(luaState, stackPos);
if (obj != null && paramType.IsAssignableFrom(obj.GetType()))
return extractNetObject;
}
return null;
}
Type GetExtractDictionaryKey(Type targetType)
{
return targetType;
}
/*
* The following functions return the value in the Lua stack
* index stackPos as the desired type if it can, or null
* otherwise.
*/
private object GetAsSbyte(LuaState luaState, int stackPos)
{
sbyte retVal = (sbyte)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumber(stackPos))
return null;
return retVal;
}
private object GetAsByte(LuaState luaState, int stackPos)
{
byte retVal = (byte)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumber(stackPos))
return null;
return retVal;
}
private object GetAsShort(LuaState luaState, int stackPos)
{
short retVal = (short)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumber(stackPos))
return null;
return retVal;
}
private object GetAsUshort(LuaState luaState, int stackPos)
{
ushort retVal = (ushort)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsInt(LuaState luaState, int stackPos)
{
if (!luaState.IsNumericType(stackPos))
return null;
int retVal = (int)luaState.ToNumber(stackPos);
return retVal;
}
private object GetAsUint(LuaState luaState, int stackPos)
{
uint retVal = (uint)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsLong(LuaState luaState, int stackPos)
{
long retVal = (long)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsUlong(LuaState luaState, int stackPos)
{
ulong retVal = (ulong)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsDouble(LuaState luaState, int stackPos)
{
double retVal = luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsChar(LuaState luaState, int stackPos)
{
char retVal = (char)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsFloat(LuaState luaState, int stackPos)
{
float retVal = (float)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsDecimal(LuaState luaState, int stackPos)
{
decimal retVal = (decimal)luaState.ToNumber(stackPos);
if (retVal == 0 && !luaState.IsNumericType(stackPos))
return null;
return retVal;
}
private object GetAsBoolean(LuaState luaState, int stackPos)
{
return luaState.ToBoolean(stackPos);
}
private object GetAsCharArray(LuaState luaState, int stackPos)
{
if (!luaState.IsString(stackPos))
return null;
string retVal = luaState.ToString(stackPos);
return retVal.ToCharArray();
}
private object GetAsString(LuaState luaState, int stackPos)
{
if (!luaState.IsString(stackPos))
return null;
string retVal = luaState.ToString(stackPos);
return retVal;
}
private object GetAsTable(LuaState luaState, int stackPos)
{
return translator.GetTable(luaState, stackPos);
}
private object GetAsFunction(LuaState luaState, int stackPos)
{
return translator.GetFunction(luaState, stackPos);
}
private object GetAsUserdata(LuaState luaState, int stackPos)
{
return translator.GetUserData(luaState, stackPos);
}
public object GetAsObject(LuaState luaState, int stackPos)
{
if (luaState.Type(stackPos) == LuaType.Table)
{
if (luaState.GetMetaField(stackPos, "__index") != LuaType.Nil)
{
if (luaState.CheckMetaTable(-1, translator.Tag))
{
luaState.Insert(stackPos);
luaState.Remove(stackPos + 1);
}
else
luaState.SetTop(-2);
}
}
object obj = translator.GetObject(luaState, stackPos);
return obj;
}
public object GetAsNetObject(LuaState luaState, int stackPos)
{
object obj = translator.GetNetObject(luaState, stackPos);
if (obj == null && luaState.Type(stackPos) == LuaType.Table)
{
if (luaState.GetMetaField(stackPos, "__index") != LuaType.Nil)
{
if (luaState.CheckMetaTable(-1, translator.Tag))
{
luaState.Insert(stackPos);
luaState.Remove(stackPos + 1);
obj = translator.GetNetObject(luaState, stackPos);
}
else
luaState.SetTop(-2);
}
}
return obj;
}
}
}
\ No newline at end of file
using System;
using KeraLua;
namespace NLua.Event
{
/// <summary>
/// Event args for hook callback event
/// </summary>
/// <author>Reinhard Ostermeier</author>
public class DebugHookEventArgs : EventArgs
{
readonly LuaDebug luaDebug;
public DebugHookEventArgs(LuaDebug luaDebug)
{
this.luaDebug = luaDebug;
}
public LuaDebug LuaDebug {
get { return luaDebug; }
}
}
}
\ No newline at end of file
using System;
namespace NLua.Event
{
public class HookExceptionEventArgs : EventArgs
{
private readonly Exception m_Exception;
public Exception Exception {
get { return m_Exception; }
}
public HookExceptionEventArgs(Exception ex)
{
m_Exception = ex;
}
}
}
\ No newline at end of file
using System;
namespace NLua.Exceptions
{
/// <summary>
/// Exceptions thrown by the Lua runtime
/// </summary>
[Serializable]
public class LuaException : Exception
{
public LuaException ()
{
}
public LuaException (string message) : base(message)
{
}
public LuaException (string message, Exception innerException) : base(message, innerException)
{
}
}
}
\ No newline at end of file
using System;
namespace NLua.Exceptions
{
/// <summary>
/// Exceptions thrown by the Lua runtime because of errors in the script
/// </summary>
///
[Serializable]
public class LuaScriptException : LuaException
{
/// <summary>
/// Returns true if the exception has occured as the result of a .NET exception in user code
/// </summary>
public bool IsNetException { get; private set; }
private readonly string source;
/// <summary>
/// The position in the script where the exception was triggered.
/// </summary>
#if SILVERLIGHT && !WINDOWS_PHONE
public string Source { get { return source; } }
#else
public override string Source { get { return source; } }
#endif
/// <summary>
/// Creates a new Lua-only exception.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="source">The position in the script where the exception was triggered.</param>
public LuaScriptException(string message, string source) : base(message)
{
this.source = source;
}
/// <summary>
/// Creates a new .NET wrapping exception.
/// </summary>
/// <param name="innerException">The .NET exception triggered by user-code.</param>
/// <param name="source">The position in the script where the exception was triggered.</param>
public LuaScriptException(Exception innerException, string source)
: base("A .NET exception occured in user-code", innerException)
{
this.source = source;
this.IsNetException = true;
}
public override string ToString()
{
// Prepend the error source
return GetType().FullName + ": " + source + Message;
}
}
}
\ No newline at end of file
using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace NLua.Extensions
{
static class TypeExtensions
{
public static bool HasMethod(this Type t, string name)
{
var op = t.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
return op.Any(m => m.Name == name);
}
public static bool HasAdditionOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_Addition");
}
public static bool HasSubtractionOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_Subtraction");
}
public static bool HasMultiplyOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_Multiply");
}
public static bool HasDivisionOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_Division");
}
public static bool HasModulusOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_Modulus");
}
public static bool HasUnaryNegationOperator(this Type t)
{
if (t.IsPrimitive)
return true;
// Unary - will always have only one version.
var op = t.GetMethod("op_UnaryNegation", BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
return op != null;
}
public static bool HasEqualityOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_Equality");
}
public static bool HasLessThanOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_LessThan");
}
public static bool HasLessThanOrEqualOperator(this Type t)
{
if (t.IsPrimitive)
return true;
return t.HasMethod("op_LessThanOrEqual");
}
public static MethodInfo[] GetMethods(this Type t, string name, BindingFlags flags)
{
return t.GetMethods(flags).Where(m => m.Name == name).ToArray();
}
public static MethodInfo[] GetExtensionMethods(this Type type, IEnumerable<Assembly> assemblies = null)
{
List<Type> types = new List<Type>();
types.AddRange(type.Assembly.GetTypes().Where(t => t.IsPublic));
if (assemblies != null)
{
foreach (Assembly item in assemblies)
{
if (item == type.Assembly)
continue;
types.AddRange(item.GetTypes().Where(t => t.IsPublic));
}
}
var query = from extensionType in types
where extensionType.IsSealed && !extensionType.IsGenericType && !extensionType.IsNested
from method in extensionType.GetMethods(BindingFlags.Static | BindingFlags.Public)
where method.IsDefined(typeof(ExtensionAttribute), false)
where (method.GetParameters()[0].ParameterType == type
|| type.IsSubclassOf(method.GetParameters()[0].ParameterType)
|| type.GetInterfaces().Contains(method.GetParameters()[0].ParameterType))
select method;
return query.ToArray<MethodInfo>();
}
/// <summary>
/// Extends the System.Type-type to search for a given extended MethodeName.
/// </summary>
/// <param name="MethodeName">Name of the Methode</param>
/// <returns>the found Method or null</returns>
public static MethodInfo GetExtensionMethod(this Type t, string name, IEnumerable<Assembly> assemblies = null)
{
var mi = from methode in t.GetExtensionMethods(assemblies)
where methode.Name == name
select methode;
if (!mi.Any<MethodInfo>())
return null;
else
return mi.First<MethodInfo>();
}
}
static class StringExtensions
{
public static IEnumerable<string> SplitWithEscape(this string input, char separator, char escapeCharacter)
{
int start = 0;
int index = 0;
while (index < input.Length)
{
index = input.IndexOf(separator, index);
if (index == -1)
break;
if (input[index - 1] == escapeCharacter)
{
input = input.Remove(index - 1, 1);
continue;
}
yield return input.Substring(start, index - start);
index++;
start = index;
}
yield return input.Substring(start);
}
}
}
\ No newline at end of file

using System;
using System.Runtime.InteropServices;
using KeraLua;
using LuaState=KeraLua.Lua;
namespace NLua.Extensions
{
static class LuaExtensions
{
public static bool CheckMetaTable(this LuaState state, int index, IntPtr tag)
{
if (!state.GetMetaTable(index))
return false;
state.PushLightUserData(tag);
state.RawGet(-2);
bool isNotNil = !state.IsNil(-1);
state.SetTop(-3);
return isNotNil;
}
public static void PopGlobalTable(this LuaState luaState)
{
luaState.RawSetInteger(LuaRegistry.Index, (long) LuaRegistryIndex.Globals);
}
public static void GetRef (this LuaState luaState, int reference)
{
luaState.RawGetInteger(LuaRegistry.Index, reference);
}
public static void Unref (this LuaState luaState, int reference)
{
luaState.Unref(LuaRegistry.Index, reference);
}
public static bool AreEqual(this LuaState luaState, int ref1, int ref2)
{
return luaState.Compare(ref1, ref2, LuaCompare.Equal);
}
public static IntPtr CheckUData(this LuaState state, int ud, string name)
{
IntPtr p = state.ToUserData(ud);
if (p == IntPtr.Zero)
return IntPtr.Zero;
if (!state.GetMetaTable(ud))
return IntPtr.Zero;
state.GetField(LuaRegistry.Index, name);
bool isEqual = state.RawEqual(-1, -2);
state.Pop(2);
if (isEqual)
return p;
return IntPtr.Zero;
}
public static int ToNetObject(this LuaState state, int index, IntPtr tag)
{
if (state.Type(index) != LuaType.UserData)
return -1;
IntPtr userData;
if (state.CheckMetaTable(index, tag))
{
userData = state.ToUserData(index);
if (userData != IntPtr.Zero)
return Marshal.ReadInt32(userData);
}
userData = state.CheckUData(index, "luaNet_class");
if (userData != IntPtr.Zero)
return Marshal.ReadInt32(userData);
userData = state.CheckUData(index, "luaNet_searchbase");
if (userData != IntPtr.Zero)
return Marshal.ReadInt32(userData);
userData = state.CheckUData(index, "luaNet_function");
if (userData != IntPtr.Zero)
return Marshal.ReadInt32(userData);
return -1;
}
public static void NewUData(this LuaState state, int val)
{
IntPtr pointer = state.NewUserData(Marshal.SizeOf(typeof(int)));
Marshal.WriteInt32(pointer, val);
}
public static int RawNetObj(this LuaState state, int index)
{
IntPtr pointer = state.ToUserData(index);
if (pointer == IntPtr.Zero)
return -1;
return Marshal.ReadInt32(pointer);
}
public static int CheckUObject(this LuaState state, int index, string name)
{
IntPtr udata = state.CheckUData(index, name);
if (udata == IntPtr.Zero)
return -1;
return Marshal.ReadInt32(udata);
}
public static bool IsNumericType(this LuaState state, int index)
{
return state.Type(index) == LuaType.Number;
}
}
}
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