Commit 75df6585 authored by Megax's avatar Megax
Browse files

* Tobb dolog is vissza lett alakitva LuaLIb-ben s gfoot-tol lettek atveve...

* Tobb dolog is vissza lett alakitva LuaLIb-ben s gfoot-tol lettek atveve otletek. Most jol mukodik a LuaInterface a kopiluaval.
parent 05ba53d3
/*
* 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;
using System.Threading;
using LuaInterface;
......@@ -25,17 +50,17 @@ namespace LuaRunner
// For attaching from the debugger
// Thread.Sleep(20000);
using (Lua lua = new Lua())
using(Lua lua = new Lua())
{
//lua.OpenLibs(); // steffenj: Lua 5.1.1 API change (all libs already opened in Lua constructor!)
lua.NewTable("arg");
LuaTable argc = (LuaTable)lua["arg"];
argc[-1] = "LuaRunner";
argc[0] = args[0];
for (int i = 1; i < args.Length; i++)
{
for(int i = 1; i < args.Length; i++)
argc[i] = args[i];
}
argc["n"] = args.Length - 1;
try
......@@ -43,12 +68,13 @@ namespace LuaRunner
//Console.WriteLine("DoFile(" + args[0] + ");");
lua.DoFile(args[0]);
}
catch (Exception e)
catch(Exception e)
{
// steffenj: BEGIN error message improved, output is now in decending order of importance (message, where, stacktrace)
// limit size of strack traceback message to roughly 1 console screen height
string trace = e.StackTrace;
if (e.StackTrace.Length > 1300)
if(e.StackTrace.Length > 1300)
trace = e.StackTrace.Substring(0, 1300) + " [...] (traceback cut short)";
Console.WriteLine();
......
using System.Reflection;
/*
* 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;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LuaInterface.Config;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("LuaRunner")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LuaRunner")]
[assembly: AssemblyCopyright("Copyright © 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyDescription(Consts.LuaInterfaceDescription)]
[assembly: AssemblyConfiguration(Consts.LuaInterfaceConfiguration)]
[assembly: AssemblyCompany(Consts.LuaInterfaceCompany)]
[assembly: AssemblyProduct(Consts.LuaInterfaceProduct)]
[assembly: AssemblyCopyright(Consts.LuaInterfaceCopyright)]
[assembly: AssemblyTrademark(Consts.LuaInterfaceTrademark)]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("0db73438-fb76-4991-b61d-3c072d340154")]
// Version information for an assembly consists of the following four values:
//
// Major Version
......@@ -29,5 +52,8 @@ using System.Runtime.InteropServices;
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.5.2")]
[assembly: AssemblyFileVersion("1.5.2")]
\ No newline at end of file
......@@ -22,7 +22,6 @@
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<NoWarn>3001;</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>none</DebugType>
......
......@@ -514,7 +514,6 @@ namespace KopiLua
public static void lua_pushlightuserdata (lua_State L, object p) {
lua_lock(L);
setpvalue(L.top, p);
Console.WriteLine(L.top.value.p.GetType());
api_incr_top(L);
lua_unlock(L);
}
......
......@@ -169,7 +169,6 @@ namespace KopiLua
#endif
{
f(L, ud);
Console.WriteLine(lj.status);
}
#if CATCH_EXCEPTIONS
catch
......@@ -308,10 +307,7 @@ namespace KopiLua
StkId p;
ptrdiff_t funcr = savestack(L, func);
if (!ttisfunction(tm))
{
Console.WriteLine(false);
luaG_typeerror(L, func, "call");
}
/* Open a hole inside the stack at `func' */
for (p = L.top; p > func; StkId.dec(ref p)) setobjs2s(L, p, p - 1);
incr_top(L);
......@@ -334,16 +330,13 @@ namespace KopiLua
public static int luaD_precall (lua_State L, StkId func, int nresults) {
LClosure cl;
ptrdiff_t funcr;
Console.WriteLine(15);
if (!ttisfunction(func)) /* `func' is not a function? */
func = tryfuncTM(L, func); /* check the `function' tag method */
Console.WriteLine(16);
funcr = savestack(L, func);
Console.WriteLine(20);
cl = clvalue(func).l;
Console.WriteLine(30);
L.ci.savedpc = InstructionPtr.Assign(L.savedpc);
Console.WriteLine(300);
if (cl.isC==0) { /* Lua function? prepare its call */
CallInfo ci;
StkId st, base_;
......@@ -379,7 +372,6 @@ namespace KopiLua
return PCRLUA;
}
else { /* if is a C function, call it */
Console.WriteLine(301);
CallInfo ci;
int n;
luaD_checkstack(L, LUA_MINSTACK); /* ensure minimum stack size */
......@@ -447,7 +439,6 @@ namespace KopiLua
** function position.
*/
private static void luaD_call (lua_State L, StkId func, int nResults) {
Console.WriteLine("asd");
if (++L.nCcalls >= LUAI_MAXCCALLS) {
if (L.nCcalls == LUAI_MAXCCALLS)
luaG_runerror(L, "C stack overflow");
......@@ -456,15 +447,10 @@ namespace KopiLua
}
if (luaD_precall(L, func, nResults) == PCRLUA) /* is a Lua function? */
{
Console.WriteLine("asd30");
luaV_execute(L, 1); /* call it */
Console.WriteLine("asd3");
}
L.nCcalls--;
Console.WriteLine("asd4");
luaC_checkGC(L);
Console.WriteLine("asd5");
}
......@@ -549,7 +535,6 @@ namespace KopiLua
ptrdiff_t old_errfunc = L.errfunc;
L.errfunc = ef;
status = luaD_rawrunprotected(L, func, u);
Console.WriteLine("status: " + status.ToString());
if (status != 0) { /* an error occurred? */
StkId oldtop = restorestack(L, old_top);
luaF_close(L, oldtop); /* close eventual pending closures */
......
......@@ -786,24 +786,18 @@ namespace KopiLua
public static int luaO_rawequalObj (TValue t1, TValue t2) {
Console.WriteLine("luaO_rawequalObj:" + (ttype(t1) != ttype(t2)).ToString());
if (ttype(t1) != ttype(t2)) return 0;
else switch (ttype(t1)) {
case LUA_TNIL:
Console.WriteLine("luaO_rawequalObj1:" + (1).ToString());
return 1;
case LUA_TNUMBER:
Console.WriteLine("luaO_rawequalObj2:" + (luai_numeq(nvalue(t1), nvalue(t2))).ToString());
return luai_numeq(nvalue(t1), nvalue(t2)) ? 1 : 0;
case LUA_TBOOLEAN:
Console.WriteLine("luaO_rawequalObj3:" + (bvalue(t1) == bvalue(t2)).ToString());
return bvalue(t1) == bvalue(t2) ? 1 : 0; /* boolean true must be 1....but not in C# !! */
case LUA_TLIGHTUSERDATA:
Console.WriteLine("luaO_rawequalObj4:" + (pvalue(t1) == pvalue(t2)).ToString());
return pvalue(t1) == pvalue(t2) ? 1 : 0;
default:
lua_assert(iscollectable(t1));
Console.WriteLine("luaO_rawequalObj5:" + (gcvalue(t1) == gcvalue(t2)).ToString());
return gcvalue(t1) == gcvalue(t2) ? 1 : 0;
}
}
......
......@@ -99,9 +99,8 @@ namespace KopiLua
mt = G(L).mt[ttype(o)];
break;
}
Console.WriteLine("mt: " + (mt!=null).ToString());
return ((mt!=null) ? luaH_getstr(mt, G(L).tmname[(int)event_]) : luaO_nilobject);
}
}
}
......@@ -89,7 +89,7 @@ namespace LuaInterface
internal ExtractValue checkType(LuaCore.lua_State luaState, int stackPos, Type paramType)
{
var luatype = LuaCore.lua_type(luaState, stackPos).ToLuaTypes();
var luatype = LuaLib.lua_type(luaState, stackPos);
if(paramType.IsByRef)
paramType = paramType.GetElementType();
......@@ -123,17 +123,17 @@ namespace LuaInterface
//;//an unsupported type was encountered
}
if(LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
if(LuaLib.lua_isnumber(luaState, stackPos))
return extractValues[runtimeHandleValue];
if(paramType == typeof(bool))
{
if(LuaCore.lua_isboolean(luaState, stackPos))
if(LuaLib.lua_isboolean(luaState, stackPos))
return extractValues[runtimeHandleValue];
}
else if(paramType == typeof(string))
{
if(LuaCore.lua_isstring(luaState, stackPos).ToBoolean())
if(LuaLib.lua_isstring(luaState, stackPos))
return extractValues[runtimeHandleValue];
else if(luatype == LuaTypes.Nil)
return extractNetObject; // kevinh - silently convert nil to a null string pointer
......@@ -162,12 +162,12 @@ namespace LuaInterface
// kevinh - allow nil to be silently converted to null - extractNetObject will return null when the item ain't found
return extractNetObject;
}
else if(LuaCore.lua_type(luaState, stackPos).ToLuaTypes() == LuaTypes.Table)
else if(LuaLib.lua_type(luaState, stackPos) == LuaTypes.Table)
{
if(LuaCore.luaL_getmetafield(luaState, stackPos, "__index").ToBoolean())
if(LuaLib.luaL_getmetafield(luaState, stackPos, "__index"))
{
object obj = translator.getNetObject(luaState, -1);
LuaCore.lua_settop(luaState, -2);
LuaLib.lua_settop(luaState, -2);
if(!obj.IsNull() && paramType.IsAssignableFrom(obj.GetType()))
return extractNetObject;
}
......@@ -191,8 +191,8 @@ namespace LuaInterface
*/
private object getAsSbyte(LuaCore.lua_State luaState, int stackPos)
{
sbyte retVal = (sbyte)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
sbyte retVal = (sbyte)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -200,8 +200,8 @@ namespace LuaInterface
private object getAsByte(LuaCore.lua_State luaState, int stackPos)
{
byte retVal = (byte)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
byte retVal = (byte)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -209,8 +209,8 @@ namespace LuaInterface
private object getAsShort(LuaCore.lua_State luaState, int stackPos)
{
short retVal = (short)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
short retVal = (short)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -218,8 +218,8 @@ namespace LuaInterface
private object getAsUshort(LuaCore.lua_State luaState, int stackPos)
{
ushort retVal = (ushort)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
ushort retVal = (ushort)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -227,8 +227,8 @@ namespace LuaInterface
private object getAsInt(LuaCore.lua_State luaState, int stackPos)
{
int retVal = (int)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
int retVal = (int)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -236,8 +236,8 @@ namespace LuaInterface
private object getAsUint(LuaCore.lua_State luaState, int stackPos)
{
uint retVal = (uint)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
uint retVal = (uint)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -245,8 +245,8 @@ namespace LuaInterface
private object getAsLong(LuaCore.lua_State luaState, int stackPos)
{
long retVal = (long)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
long retVal = (long)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -254,8 +254,8 @@ namespace LuaInterface
private object getAsUlong(LuaCore.lua_State luaState, int stackPos)
{
ulong retVal = (ulong)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
ulong retVal = (ulong)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -263,8 +263,8 @@ namespace LuaInterface
private object getAsDouble(LuaCore.lua_State luaState, int stackPos)
{
double retVal = LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
double retVal = LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -272,8 +272,8 @@ namespace LuaInterface
private object getAsChar(LuaCore.lua_State luaState, int stackPos)
{
char retVal = (char)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
char retVal = (char)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -281,8 +281,8 @@ namespace LuaInterface
private object getAsFloat(LuaCore.lua_State luaState, int stackPos)
{
float retVal = (float)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
float retVal = (float)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -290,8 +290,8 @@ namespace LuaInterface
private object getAsDecimal(LuaCore.lua_State luaState, int stackPos)
{
decimal retVal = (decimal)LuaCore.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaCore.lua_isnumber(luaState, stackPos).ToBoolean())
decimal retVal = (decimal)LuaLib.lua_tonumber(luaState, stackPos);
if(retVal == 0 && !LuaLib.lua_isnumber(luaState, stackPos))
return null;
return retVal;
......@@ -299,13 +299,13 @@ namespace LuaInterface
private object getAsBoolean(LuaCore.lua_State luaState, int stackPos)
{
return LuaCore.lua_toboolean(luaState, stackPos);
return LuaLib.lua_toboolean(luaState, stackPos);
}
private object getAsString(LuaCore.lua_State luaState, int stackPos)
{
string retVal = LuaCore.lua_tostring(luaState, stackPos).ToString();
if(retVal == string.Empty && !LuaCore.lua_isstring(luaState, stackPos).ToBoolean())
string retVal = LuaLib.lua_tostring(luaState, stackPos).ToString();
if(retVal == string.Empty && !LuaLib.lua_isstring(luaState, stackPos))
return null;
return retVal;
......@@ -328,17 +328,17 @@ namespace LuaInterface
public object getAsObject(LuaCore.lua_State luaState, int stackPos)
{
if(LuaCore.lua_type(luaState, stackPos).ToLuaTypes() == LuaTypes.Table)
if(LuaLib.lua_type(luaState, stackPos) == LuaTypes.Table)
{
if(LuaCore.luaL_getmetafield(luaState, stackPos, "__index").ToBoolean())
if(LuaLib.luaL_getmetafield(luaState, stackPos, "__index"))
{
if(LuaLib.luaL_checkmetatable(luaState, -1))
{
LuaCore.lua_insert(luaState, stackPos);
LuaCore.lua_remove(luaState, stackPos+1);
LuaLib.lua_insert(luaState, stackPos);
LuaLib.lua_remove(luaState, stackPos+1);
}
else
LuaCore.lua_settop(luaState, -2);
LuaLib.lua_settop(luaState, -2);
}
}
......@@ -350,18 +350,18 @@ namespace LuaInterface
{
object obj = translator.getNetObject(luaState, stackPos);
if(obj.IsNull() && LuaCore.lua_type(luaState, stackPos).ToLuaTypes() == LuaTypes.Table)
if(obj.IsNull() && LuaLib.lua_type(luaState, stackPos) == LuaTypes.Table)
{
if(LuaCore.luaL_getmetafield(luaState, stackPos, "__index").ToBoolean())
if(LuaLib.luaL_getmetafield(luaState, stackPos, "__index"))
{
if(LuaLib.luaL_checkmetatable(luaState, -1))
{
LuaCore.lua_insert(luaState, stackPos);
LuaCore.lua_remove(luaState, stackPos+1);
LuaLib.lua_insert(luaState, stackPos);
LuaLib.lua_remove(luaState, stackPos+1);
obj = translator.getNetObject(luaState, stackPos);
}
else
LuaCore.lua_settop(luaState, -2);
LuaLib.lua_settop(luaState, -2);
}
}
......
/*
* This file is part of LuaInterface.
*
* 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.Config
{
public static class Consts
{
public const string LuaInterfaceDescription = "Bridge between the Lua runtime and the CLR";
#if DEBUG
public const string LuaInterfaceConfiguration = "Debug";
#else
public const string LuaInterfaceConfiguration = "Release";
#endif
public const string LuaInterfaceCompany = "LuaInterface Productions";
public const string LuaInterfaceProduct = "LuaInterface";
public const string LuaInterfaceCopyright = "Copyright 2003-2008 Fabio Mascarenhas, Kevin Hesterm and 2012 Megax";
public const string LuaInterfaceTrademark = "MIT license";
public const string LuaInterfaceVersion = "2.0.4";
public const string LuaInterfaceFileVersion = "2.0.4.0";
}
}
\ No newline at end of file
......@@ -154,30 +154,30 @@ namespace LuaInterface
public Lua()
{
luaState = LuaCore.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone)
//LuaCore.luaopen_base(luaState); // steffenj: luaopen_* no longer used
LuaCore.luaL_openlibs(luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
LuaCore.lua_pushstring(luaState, "LUAINTERFACE LOADED");
LuaCore.lua_pushboolean(luaState, 1);
LuaCore.lua_settable(luaState, (int)PseudoIndex.Registry);
LuaCore.lua_newtable(luaState);
LuaCore.lua_setglobal(luaState, "luanet");
LuaCore.lua_pushvalue(luaState, (int)PseudoIndex.Globals);
LuaCore.lua_getglobal(luaState, "luanet");
LuaCore.lua_pushstring(luaState, "getmetatable");
LuaCore.lua_getglobal(luaState, "getmetatable");
LuaCore.lua_settable(luaState, -3);
LuaCore.lua_replace(luaState, (int)PseudoIndex.Globals);
luaState = LuaLib.luaL_newstate(); // steffenj: Lua 5.1.1 API change (lua_open is gone)
//LuaLib.luaopen_base(luaState); // steffenj: luaopen_* no longer used
LuaLib.luaL_openlibs(luaState); // steffenj: Lua 5.1.1 API change (luaopen_base is gone, just open all libs right here)
LuaLib.lua_pushstring(luaState, "LUAINTERFACE LOADED");
LuaLib.lua_pushboolean(luaState, true);
LuaLib.lua_settable(luaState, (int)LuaIndexes.Registry);
LuaLib.lua_newtable(luaState);
LuaLib.lua_setglobal(luaState, "luanet");
LuaLib.lua_pushvalue(luaState, (int)LuaIndexes.Globals);
LuaLib.lua_getglobal(luaState, "luanet");
LuaLib.lua_pushstring(luaState, "getmetatable");
LuaLib.lua_getglobal(luaState, "getmetatable");
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_replace(luaState, (int)LuaIndexes.Globals);
translator = new ObjectTranslator(this, luaState);
LuaCore.lua_replace(luaState, (int)PseudoIndex.Globals);
LuaLib.lua_replace(luaState, (int)LuaIndexes.Globals);
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
panicCallback = new LuaCore.lua_CFunction(PanicCallback);
LuaCore.lua_atpanic(luaState, panicCallback);
LuaLib.lua_atpanic(luaState, panicCallback);
//LuaCore.lua_atlock(luaState, lockCallback = new LuaCore.lua_CFunction(LockCallback));
//LuaCore.lua_atunlock(luaState, unlockCallback = new LuaCore.lua_CFunction(UnlockCallback));
//LuaLib.lua_atlock(luaState, lockCallback = new LuaCore.lua_CFunction(LockCallback));
//LuaLib.lua_atunlock(luaState, unlockCallback = new LuaCore.lua_CFunction(UnlockCallback));
}
/*
......@@ -185,29 +185,29 @@ namespace LuaInterface
*/
public Lua(LuaCore.lua_State lState)
{
LuaCore.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaCore.lua_gettable(lState, (int)PseudoIndex.Registry);
LuaLib.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaLib.lua_gettable(lState, (int)LuaIndexes.Registry);
if(LuaCore.lua_toboolean(lState, -1).ToBoolean())
if(LuaLib.lua_toboolean(lState, -1))
{
LuaCore.lua_settop(lState, -2);
LuaLib.lua_settop(lState, -2);
throw new LuaException("There is already a LuaInterface.Lua instance associated with this Lua state");
}
else
{
LuaCore.lua_settop(lState, -2);
LuaCore.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaCore.lua_pushboolean(lState, 1);
LuaCore.lua_settable(lState, (int)PseudoIndex.Registry);
LuaLib.lua_settop(lState, -2);
LuaLib.lua_pushstring(lState, "LUAINTERFACE LOADED");
LuaLib.lua_pushboolean(lState, true);
LuaLib.lua_settable(lState, (int)LuaIndexes.Registry);
luaState = lState;
LuaCore.lua_pushvalue(lState, (int)PseudoIndex.Globals);
LuaCore.lua_getglobal(lState, "luanet");
LuaCore.lua_pushstring(lState, "getmetatable");
LuaCore.lua_getglobal(lState, "getmetatable");
LuaCore.lua_settable(lState, -3);
LuaCore.lua_replace(lState, (int)PseudoIndex.Globals);
LuaLib.lua_pushvalue(lState, (int)LuaIndexes.Globals);
LuaLib.lua_getglobal(lState, "luanet");
LuaLib.lua_pushstring(lState, "getmetatable");
LuaLib.lua_getglobal(lState, "getmetatable");
LuaLib.lua_settable(lState, -3);
LuaLib.lua_replace(lState, (int)LuaIndexes.Globals);
translator = new ObjectTranslator(this, luaState);
LuaCore.lua_replace(lState, (int)PseudoIndex.Globals);
LuaLib.lua_replace(lState, (int)LuaIndexes.Globals);
LuaLib.luaL_dostring(lState, Lua.init_luanet); // steffenj: lua_dostring renamed to luaL_dostring
}
......@@ -249,8 +249,8 @@ namespace LuaInterface
static int PanicCallback(LuaCore.lua_State luaState)
{
// string desc = LuaCore.lua_tostring(luaState, 1);
string reason = string.Format("unprotected error in call to Lua API ({0})", LuaCore.lua_tostring(luaState, -1));
// string desc = LuaLib.lua_tostring(luaState, 1);
string reason = string.Format("unprotected error in call to Lua API ({0})", LuaLib.lua_tostring(luaState, -1));
// lua_tostring(L, -1);
throw new LuaException(reason);
}
......@@ -262,7 +262,7 @@ namespace LuaInterface
private void ThrowExceptionFromError(int oldTop)
{
object err = translator.getObject(luaState, -1);
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
// A pre-wrapped exception - just rethrow it (stack trace of InnerException will be preserved)
var luaEx = err as LuaScriptException;
......@@ -289,7 +289,7 @@ namespace LuaInterface
if(!caughtExcept.IsNull())
{
translator.throwError(luaState, caughtExcept);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
else
......@@ -304,7 +304,7 @@ namespace LuaInterface
/// <returns></returns>
public LuaFunction LoadString(string chunk, string name)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
executing = true;
try
......@@ -329,9 +329,9 @@ namespace LuaInterface
/// <returns></returns>
public LuaFunction LoadFile(string fileName)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
if(LuaCore.luaL_loadfile(luaState, fileName) != 0)
if(LuaLib.luaL_loadfile(luaState, fileName) != 0)
ThrowExceptionFromError(oldTop);
var result = translator.getFunction(luaState, -1);
......@@ -345,7 +345,7 @@ namespace LuaInterface
*/
public object[] DoString(string chunk)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
if(LuaLib.luaL_loadbuffer(luaState, chunk, "chunk") == 0)
{
......@@ -353,7 +353,7 @@ namespace LuaInterface
try
{
if(LuaCore.lua_pcall(luaState, 0, -1, 0) == 0)
if(LuaLib.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop);
else
ThrowExceptionFromError(oldTop);
......@@ -377,14 +377,14 @@ namespace LuaInterface
/// <returns></returns>
public object[] DoString(string chunk, string chunkName)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
executing = true;
if(LuaLib.luaL_loadbuffer(luaState, chunk, chunkName) == 0)
{
try
{
if(LuaCore.lua_pcall(luaState, 0, -1, 0) == 0)
if(LuaLib.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop);
else
ThrowExceptionFromError(oldTop);
......@@ -406,15 +406,15 @@ namespace LuaInterface
*/
public object[] DoFile(string fileName)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
if(LuaCore.luaL_loadfile(luaState, fileName) == 0)
if(LuaLib.luaL_loadfile(luaState, fileName) == 0)
{
executing = true;
try
{
if(LuaCore.lua_pcall(luaState, 0, -1, 0) == 0)
if(LuaLib.lua_pcall(luaState, 0, -1, 0) == 0)
return translator.popValues(luaState, oldTop);
else
ThrowExceptionFromError(oldTop);
......@@ -440,9 +440,9 @@ namespace LuaInterface
get
{
object returnValue = null;
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
string[] path = fullPath.Split(new char[] { '.' });
LuaCore.lua_getglobal(luaState, path[0]);
LuaLib.lua_getglobal(luaState, path[0]);
returnValue = translator.getObject(luaState, -1);
if(path.Length>1)
......@@ -452,28 +452,28 @@ namespace LuaInterface
returnValue = getObject(remainingPath);
}
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
return returnValue;
}
set
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
string[] path = fullPath.Split(new char[] { '.' });
if(path.Length == 1)
{
translator.push(luaState, value);
LuaCore.lua_setglobal(luaState, fullPath);
LuaLib.lua_setglobal(luaState, fullPath);
}
else
{
LuaCore.lua_getglobal(luaState, path[0]);
LuaLib.lua_getglobal(luaState, path[0]);
string[] remainingPath = new string[path.Length-1];
Array.Copy(path, 1, remainingPath, 0, path.Length-1);
setObject(remainingPath, value);
}
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
// Globals auto-complete
if(value.IsNull())
......@@ -581,8 +581,8 @@ namespace LuaInterface
for(int i = 0; i < remainingPath.Length; i++)
{
LuaCore.lua_pushstring(luaState, remainingPath[i]);
LuaCore.lua_gettable(luaState, -2);
LuaLib.lua_pushstring(luaState, remainingPath[i]);
LuaLib.lua_gettable(luaState, -2);
returnValue = translator.getObject(luaState, -1);
if(returnValue.IsNull())
......@@ -632,7 +632,6 @@ namespace LuaInterface
{
object obj = this[fullPath];
return (obj is LuaCore.lua_CFunction ? new LuaFunction((LuaCore.lua_CFunction)obj, this) : (LuaFunction)obj);
//return (obj is LuaCore.lua_CFunction ? new LuaFunction((LuaCore.lua_CFunction)obj, this) : /*(LuaFunction)*/new LuaFunction(obj.GetHashCode(), this));
}
/*
......@@ -661,9 +660,9 @@ namespace LuaInterface
internal object[] callFunction(object function, object[] args, Type[] returnTypes)
{
int nArgs = 0;
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
if(!LuaCore.lua_checkstack(luaState, args.Length+6).ToBoolean())
if(!LuaLib.lua_checkstack(luaState, args.Length+6))
throw new LuaException("Lua stack overflow");
translator.push(luaState, function);
......@@ -680,7 +679,7 @@ namespace LuaInterface
try
{
int error = LuaCore.lua_pcall(luaState, nArgs, -1, 0);
int error = LuaLib.lua_pcall(luaState, nArgs, -1, 0);
if(error != 0)
ThrowExceptionFromError(oldTop);
}
......@@ -699,13 +698,13 @@ namespace LuaInterface
{
for(int i = 0; i < remainingPath.Length-1; i++)
{
LuaCore.lua_pushstring(luaState, remainingPath[i]);
LuaCore.lua_gettable(luaState, -2);
LuaLib.lua_pushstring(luaState, remainingPath[i]);
LuaLib.lua_gettable(luaState, -2);
}
LuaCore.lua_pushstring(luaState, remainingPath[remainingPath.Length-1]);
LuaLib.lua_pushstring(luaState, remainingPath[remainingPath.Length-1]);
translator.push(luaState, val);
LuaCore.lua_settable(luaState, -3);
LuaLib.lua_settable(luaState, -3);
}
/*
......@@ -715,45 +714,45 @@ namespace LuaInterface
public void NewTable(string fullPath)
{
string[] path = fullPath.Split(new char[] { '.' });
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
if(path.Length == 1)
{
LuaCore.lua_newtable(luaState);
LuaCore.lua_setglobal(luaState, fullPath);
LuaLib.lua_newtable(luaState);
LuaLib.lua_setglobal(luaState, fullPath);
}
else
{
LuaCore.lua_getglobal(luaState, path[0]);
LuaLib.lua_getglobal(luaState, path[0]);
for(int i = 1; i < path.Length-1; i++)
{
LuaCore.lua_pushstring(luaState, path[i]);
LuaCore.lua_gettable(luaState, -2);
LuaLib.lua_pushstring(luaState, path[i]);
LuaLib.lua_gettable(luaState, -2);
}
LuaCore.lua_pushstring(luaState, path[path.Length-1]);
LuaCore.lua_newtable(luaState);
LuaCore.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, path[path.Length-1]);
LuaLib.lua_newtable(luaState);
LuaLib.lua_settable(luaState, -3);
}
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
}
public ListDictionary GetTableDict(LuaTable table)
{
var dict = new ListDictionary();
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
translator.push(luaState, table);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
while(LuaCore.lua_next(luaState, -2) != 0)
while(LuaLib.lua_next(luaState, -2) != 0)
{
dict[translator.getObject(luaState, -2)] = translator.getObject(luaState, -1);
LuaCore.lua_settop(luaState, -2);
LuaLib.lua_settop(luaState, -2);
}
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
return dict;
}
......@@ -825,7 +824,7 @@ namespace LuaInterface
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try
{
return LuaCore.lua_getstack(luaState, level, luaDebug) != 0;
return LuaLib.lua_getstack(luaState, level, luaDebug) != 0;
}
finally
{
......@@ -847,7 +846,7 @@ namespace LuaInterface
System.Runtime.InteropServices.Marshal.StructureToPtr(luaDebug, ld, false);
try
{
return LuaCore.lua_getinfo(luaState, what, ld);
return LuaLib.lua_getinfo(luaState, what, ld);
}
finally
{
......@@ -953,7 +952,7 @@ namespace LuaInterface
/// <author>Reinhard Ostermeier</author>
public object Pop()
{
int top = LuaCore.lua_gettop(luaState);
int top = LuaLib.lua_gettop(luaState);
return translator.popValues(luaState, top - 1)[0];
}
......@@ -970,7 +969,6 @@ namespace LuaInterface
internal void dispose(int reference)
{
///////////// if(luaState != LuaCore.lua_State.Zero)
if(!luaState.IsNull()) //Fix submitted by Qingrui Li
LuaLib.lua_unref(luaState, reference);
}
......@@ -981,12 +979,12 @@ namespace LuaInterface
*/
internal object rawGetObject(int reference, string field)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
LuaLib.lua_getref(luaState, reference);
LuaCore.lua_pushstring(luaState, field);
LuaCore.lua_rawget(luaState, -2);
LuaLib.lua_pushstring(luaState, field);
LuaLib.lua_rawget(luaState, -2);
object obj = translator.getObject(luaState, -1);
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
return obj;
}
......@@ -995,10 +993,10 @@ namespace LuaInterface
*/
internal object getObject(int reference, string field)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
LuaLib.lua_getref(luaState, reference);
object returnValue = getObject(field.Split(new char[] {'.'}));
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
return returnValue;
}
......@@ -1008,12 +1006,12 @@ namespace LuaInterface
internal object getObject(int reference, object field)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
LuaLib.lua_getref(luaState, reference);
translator.push(luaState, field);
LuaCore.lua_gettable(luaState, -2);
LuaLib.lua_gettable(luaState, -2);
object returnValue = translator.getObject(luaState, -1);
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
return returnValue;
}
......@@ -1023,10 +1021,10 @@ namespace LuaInterface
*/
internal void setObject(int reference, string field, object val)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
LuaLib.lua_getref(luaState, reference);
setObject(field.Split(new char[] {'.'}), val);
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
}
/*
......@@ -1035,12 +1033,12 @@ namespace LuaInterface
*/
internal void setObject(int reference, object field, object val)
{
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
LuaLib.lua_getref(luaState, reference);
translator.push(luaState, field);
translator.push(luaState, val);
LuaCore.lua_settable(luaState, -3);
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_settop(luaState, oldTop);
}
/*
......@@ -1050,12 +1048,12 @@ 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)
{
// We leave nothing on the stack when we are done
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
var wrapper = new LuaMethodWrapper(translator, target, function.DeclaringType, function);
translator.push(luaState, new LuaCore.lua_CFunction(wrapper.call));
this[path] = translator.getObject(luaState, -1);
var f = GetFunction(path);
LuaCore.lua_settop(luaState, oldTop);
LuaLib.lua_settop(luaState, oldTop);
return f;
}
......@@ -1064,11 +1062,11 @@ namespace LuaInterface
*/
internal bool compareRef(int ref1, int ref2)
{
int top = LuaCore.lua_gettop(luaState);
int top = LuaLib.lua_gettop(luaState);
LuaLib.lua_getref(luaState, ref1);
LuaLib.lua_getref(luaState, ref2);
int equal = LuaCore.lua_equal(luaState, -1, -2);
LuaCore.lua_settop(luaState, top);
int equal = LuaLib.lua_equal(luaState, -1, -2);
LuaLib.lua_settop(luaState, top);
return (equal != 0);
}
......
......@@ -61,7 +61,6 @@
<Compile Include="Metatables.cs" />
<Compile Include="ObjectTranslator.cs" />
<Compile Include="ProxyType.cs" />
<Compile Include="LuaLib\LuaLib.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="LuaBase.cs" />
<Compile Include="LuaFunction.cs" />
......@@ -85,8 +84,6 @@
<Compile Include="LuaLib\LuaEnums.cs" />
<Compile Include="LuaLib\References.cs" />
<Compile Include="LuaLib\LuaTypes.cs" />
<Compile Include="LuaLib\GCOption.cs" />
<Compile Include="LuaLib\PseudoIndex.cs" />
<Compile Include="Method\MethodCache.cs" />
<Compile Include="Method\MethodArgs.cs" />
<Compile Include="Method\LuaMethodWrapper.cs" />
......@@ -95,6 +92,10 @@
<Compile Include="Method\LuaEventHandler.cs" />
<Compile Include="Method\LuaDelegate.cs" />
<Compile Include="Method\LuaClassHelper.cs" />
<Compile Include="LuaLib\LuaIndexes.cs" />
<Compile Include="LuaLib\GCOptions.cs" />
<Compile Include="LuaLib\LuaLib.cs" />
<Compile Include="Config\LuaInterfaceConfig.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
......@@ -116,5 +117,6 @@
<Folder Include="Event\" />
<Folder Include="Exceptions\" />
<Folder Include="Method\" />
<Folder Include="Config\" />
</ItemGroup>
</Project>
......@@ -28,7 +28,7 @@ using System;
namespace LuaInterface
{
public enum GCOption : int
public enum GCOptions : int
{
/// <summary>
/// Stops the garbage collector.
......
......@@ -28,7 +28,7 @@ using System;
namespace LuaInterface
{
public enum PseudoIndex : int
public enum LuaIndexes : int
{
Registry = (-10000),
Environment = (-10001),
......
......@@ -26,217 +26,502 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using LuaInterface.Extensions;
namespace LuaInterface
{
using LuaCore = KopiLua.Lua;
public static class LuaLib
public class LuaLib
{
private static int tag = 0;
// Not sure of the purpose of this, but I'm keeping it -kevinh
private static object tag = 0;
public static LuaTypes ToLuaTypes(this int type)
// steffenj: BEGIN additional Lua API functions new in Lua 5.1
public static int lua_gc(LuaCore.lua_State luaState, GCOptions what, int data)
{
return (LuaTypes)type;
return LuaCore.lua_gc(luaState, (int)what, data);
}
public static LuaEnums ToLuaEnums(this int lenum)
public static string lua_typename(LuaCore.lua_State luaState, LuaTypes type)
{
return (LuaEnums)lenum;
return LuaCore.lua_typename(luaState, (int)type).ToString();
}
public static bool ToBoolean(this int number)
public static string luaL_typename(LuaCore.lua_State luaState, int stackPos)
{
return number == 1;
return lua_typename(luaState, lua_type(luaState, stackPos));
}
#region Core Library
/// <summary>
/// Pushes a C function onto the stack. This function receives a pointer to a C function and pushes onto the stack a Lua value of type function that, when called, invokes the corresponding C function.
/// </summary>
/// <param name="state">
/// A <see cref="IntPtr"/>
/// </param>
/// <param name="fn">
/// A <see cref="CallbackFunction"/>
/// </param>
public static void lua_pushcfunction(LuaCore.lua_State state, LuaCore.lua_CFunction fn)
public static void luaL_error(LuaCore.lua_State luaState, string message)
{
LuaCore.lua_pushcclosure(state, fn, 0);
LuaCore.luaL_error(luaState, message);
}
#endregion
#region Auxiliary Library
/// <summary>
/// Loads and runs the given file.
/// </summary>
/// <param name="state">
/// A <see cref="IntPtr"/>
/// </param>
/// <param name="filename">
/// A <see cref="System.String"/>
/// </param>
/// <returns>
/// A <see cref="System.Boolean"/>
/// </returns>
public static bool luaL_dofile(LuaCore.lua_State state, string filename)
public static void luaL_where(LuaCore.lua_State luaState, int level)
{
return (LuaCore.luaL_loadfile(state, filename).ToLuaEnums() == LuaEnums.Ok) && (LuaCore.lua_pcall(state, 0, (int)LuaEnums.MultiRet, 0).ToLuaEnums() == LuaEnums.Ok);
LuaCore.luaL_where(luaState, level);
}
/// <summary>
/// Loads and runs the given string.
/// </summary>
/// <param name="state">
/// A <see cref="IntPtr"/>
/// </param>
/// <param name="chunk">
/// A <see cref="System.String"/>
/// </param>
/// <returns>
/// A <see cref="System.Boolean"/>
/// </returns>
public static bool luaL_dostring(LuaCore.lua_State state, string chunk)
// steffenj: BEGIN Lua 5.1.1 API change (lua_open replaced by luaL_newstate)
public static LuaCore.lua_State luaL_newstate()
{
return (LuaCore.luaL_loadstring(state, chunk).ToLuaEnums() == LuaEnums.Ok) && (LuaCore.lua_pcall(state, 0, (int)LuaEnums.MultiRet, 0).ToLuaEnums() == LuaEnums.Ok);
return LuaCore.luaL_newstate();
}
public static LuaEnums luaL_loadbuffer(LuaCore.lua_State luaState, string buff, string name)
// steffenj: BEGIN Lua 5.1.1 API change (new function luaL_openlibs)
public static void luaL_openlibs(LuaCore.lua_State luaState)
{
var result = LuaCore.luaL_loadbuffer(luaState, buff, (uint)buff.Length, name).ToLuaEnums();
LuaCore.luaL_openlibs(luaState);
}
// steffenj: END Lua 5.1.1 API change (lua_strlen is now lua_objlen)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dostring is now a macro luaL_dostring)
public static int luaL_loadstring(LuaCore.lua_State luaState, string chunk)
{
return LuaCore.luaL_loadstring(luaState, chunk);
}
public static int luaL_dostring(LuaCore.lua_State luaState, string chunk)
{
int result = luaL_loadstring(luaState, chunk);
if(result != 0)
return result;
return lua_pcall(luaState, 0, -1, 0);
}
public static bool luaL_checkmetatable(LuaCore.lua_State luaState,int index)
/// <summary>DEPRECATED - use luaL_dostring(LuaCore.lua_State luaState, string chunk) instead!</summary>
public static int lua_dostring(LuaCore.lua_State luaState, string chunk)
{
bool retVal = false;
Console.WriteLine("v: " + luaState.tt.ToString());
return luaL_dostring(luaState, chunk);
}
if(LuaCore.lua_getmetatable(luaState,index) != 0)
// steffenj: END Lua 5.1.1 API change (lua_dostring is now a macro luaL_dostring)
// steffenj: BEGIN Lua 5.1.1 API change (lua_newtable is gone, lua_createtable is new)
public static void lua_createtable(LuaCore.lua_State luaState, int narr, int nrec)
{
LuaCore.lua_pushlightuserdata(luaState, tag);
LuaCore.lua_rawget(luaState, -2);
retVal = !LuaCore.lua_isnil(luaState, -1);
LuaCore.lua_settop(luaState, -3);
LuaCore.lua_createtable(luaState, narr, nrec);
}
return retVal;
public static void lua_newtable(LuaCore.lua_State luaState)
{
lua_createtable(luaState, 0, 0);
}
public static int luanet_gettag()
// steffenj: END Lua 5.1.1 API change (lua_newtable is gone, lua_createtable is new)
// steffenj: BEGIN Lua 5.1.1 API change (lua_dofile now in LuaLib as luaL_dofile macro)
public static int luaL_dofile(LuaCore.lua_State luaState, string fileName)
{
return tag;
int result = LuaCore.luaL_loadfile(luaState, fileName);
if(result != 0)
return result;
return LuaCore.lua_pcall(luaState, 0, -1, 0);
}
// steffenj: END Lua 5.1.1 API change (lua_dofile now in LuaLib as luaL_dofile)
public static void lua_getglobal(LuaCore.lua_State luaState, string name)
{
lua_pushstring(luaState, name);
LuaCore.lua_gettable(luaState, (int)LuaIndexes.Globals);
}
public static void lua_setglobal(LuaCore.lua_State luaState, string name)
{
lua_pushstring(luaState,name);
lua_insert(luaState,-2);
lua_settable(luaState, (int)LuaIndexes.Globals);
}
public static void lua_settop(LuaCore.lua_State luaState, int newTop)
{
LuaCore.lua_settop(luaState, newTop);
}
public static void lua_pop(LuaCore.lua_State luaState, int amount)
{
lua_settop(luaState, -(amount) - 1);
}
public static void lua_insert(LuaCore.lua_State luaState, int newTop)
{
LuaCore.lua_insert(luaState, newTop);
}
public static void lua_remove(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_remove(luaState, index);
}
public static void lua_gettable(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_gettable(luaState, index);
}
public static void lua_rawget(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_rawget(luaState, index);
}
public static void lua_settable(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_settable(luaState, index);
}
public static void lua_rawset(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_rawset(luaState, index);
}
public static void lua_setmetatable(LuaCore.lua_State luaState, int objIndex)
{
LuaCore.lua_setmetatable(luaState, objIndex);
}
public static int lua_getmetatable(LuaCore.lua_State luaState, int objIndex)
{
return LuaCore.lua_getmetatable(luaState, objIndex);
}
public static int lua_equal(LuaCore.lua_State luaState, int index1, int index2)
{
return LuaCore.lua_equal(luaState, index1, index2);
}
public static void lua_pushvalue(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_pushvalue(luaState, index);
}
public static void lua_replace(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_replace(luaState, index);
}
public static int lua_gettop(LuaCore.lua_State luaState)
{
return LuaCore.lua_gettop(luaState);
}
public static LuaTypes lua_type(LuaCore.lua_State luaState, int index)
{
return (LuaTypes) LuaCore.lua_type(luaState, index);
}
public static bool lua_isnil(LuaCore.lua_State luaState, int index)
{
return lua_type(luaState, index) == LuaTypes.Nil;
}
public static bool lua_isnumber(LuaCore.lua_State luaState, int index)
{
return lua_type(luaState, index) == LuaTypes.Number;
}
public static bool lua_isboolean(LuaCore.lua_State luaState, int index)
{
return lua_type(luaState, index) == LuaTypes.Boolean;
}
public static int luaL_ref(LuaCore.lua_State luaState, int registryIndex)
{
return LuaCore.luaL_ref(luaState, registryIndex);
}
public static int lua_ref(LuaCore.lua_State luaState, int lockRef)
{
return lockRef != 0 ? luaL_ref(luaState, (int)LuaIndexes.Registry) : 0;
}
public static void lua_rawgeti(LuaCore.lua_State luaState, int tableIndex, int index)
{
LuaCore.lua_rawgeti(luaState, tableIndex, index);
}
public static void lua_rawseti(LuaCore.lua_State luaState, int tableIndex, int index)
{
LuaCore.lua_rawseti(luaState, tableIndex, index);
}
public static object lua_newuserdata(LuaCore.lua_State luaState, int size)
{
return LuaCore.lua_newuserdata(luaState, (uint)size);
}
public static object lua_touserdata(LuaCore.lua_State luaState, int index)
{
return LuaCore.lua_touserdata(luaState, index);
}
public static void lua_getref(LuaCore.lua_State luaState, int reference)
{
LuaCore.lua_rawgeti(luaState, (int)PseudoIndex.Registry, reference);
lua_rawgeti(luaState, (int)LuaIndexes.Registry, reference);
}
public static void lua_unref(LuaCore.lua_State luaState, int reference)
{
LuaCore.luaL_unref(luaState, (int)PseudoIndex.Registry, reference);
LuaCore.luaL_unref(luaState, (int)LuaIndexes.Registry, reference);
}
public static int luanet_rawnetobj(LuaCore.lua_State luaState, int obj)
public static bool lua_isstring(LuaCore.lua_State luaState, int index)
{
//int udata = (int)LuaCore.lua_touserdata2(luaState, obj);
int udata = fourBytesToInt(LuaCore.lua_touserdata(luaState, obj) as byte[]);
return udata != 0 ? udata : -1;
return LuaCore.lua_isstring(luaState, index) != 0;
}
public static bool lua_iscfunction(LuaCore.lua_State luaState, int index)
{
return LuaCore.lua_iscfunction(luaState, index);
}
public static void lua_pushnil(LuaCore.lua_State luaState)
{
LuaCore.lua_pushnil(luaState);
}
public static void lua_call(LuaCore.lua_State luaState, int nArgs, int nResults)
{
LuaCore.lua_call(luaState, nArgs, nResults);
}
public static int lua_pcall(LuaCore.lua_State luaState, int nArgs, int nResults, int errfunc)
{
return LuaCore.lua_pcall(luaState, nArgs, nResults, errfunc);
}
public static LuaCore.lua_CFunction lua_tocfunction(LuaCore.lua_State luaState, int index)
{
return LuaCore.lua_tocfunction(luaState, index);
}
public static double lua_tonumber(LuaCore.lua_State luaState, int index)
{
return LuaCore.lua_tonumber(luaState, index);
}
public static bool lua_toboolean(LuaCore.lua_State luaState, int index)
{
return LuaCore.lua_toboolean(luaState, index) != 0;
}
public static string lua_tostring(LuaCore.lua_State luaState, int index)
{
#if true
// FIXME use the same format string as lua i.e. LUA_NUMBER_FMT
var t = lua_type(luaState, index);
if(t == LuaTypes.Number)
return string.Format("{0}", lua_tonumber(luaState, index));
else if(t == LuaTypes.String)
{
uint strlen;
return LuaCore.lua_tolstring(luaState, index, out strlen).ToString();
}
else if(t == LuaTypes.Nil)
return null; // treat lua nulls to as C# nulls
else
return "0"; // Because luaV_tostring does this
#else
size_t strlen;
// Note! This method will _change_ the representation of the object on the stack to a string.
// We do not want this behavior so we do the conversion ourselves
const char *str = LuaCore.lua_tolstring(luaState, index, &strlen);
if (str)
return Marshal::PtrToStringAnsi(IntPtr((char *) str), strlen);
else
return nullptr; // treat lua nulls to as C# nulls
#endif
}
public static void lua_atpanic(LuaCore.lua_State luaState, LuaCore.lua_CFunction panicf)
{
LuaCore.lua_atpanic(luaState, (LuaCore.lua_CFunction)panicf);
}
public static void lua_pushstdcallcfunction(LuaCore.lua_State luaState, LuaCore.lua_CFunction function)
{
lua_pushcfunction(luaState, function);
LuaCore.lua_pushcfunction(luaState, function);
}
public static void lua_pushnumber(LuaCore.lua_State luaState, double number)
{
LuaCore.lua_pushnumber(luaState, number);
}
public static void lua_pushboolean(LuaCore.lua_State luaState, bool value)
{
LuaCore.lua_pushboolean(luaState, value ? 1 : 0);
}
public static void lua_pushstring(LuaCore.lua_State luaState, string str)
{
LuaCore.lua_pushstring(luaState, str);
}
public static int luaL_newmetatable(LuaCore.lua_State luaState, string meta)
{
return LuaCore.luaL_newmetatable(luaState, meta);
}
// steffenj: BEGIN Lua 5.1.1 API change (luaL_getmetatable is now a macro using lua_getfield)
public static void lua_getfield(LuaCore.lua_State luaState, int stackPos, string meta)
{
LuaCore.lua_getfield(luaState, stackPos, meta);
}
public static void luaL_getmetatable(LuaCore.lua_State luaState, string meta)
{
lua_getfield(luaState, (int)LuaIndexes.Registry, meta);
}
public static int checkudata_raw(LuaCore.lua_State luaState, int ud, string tname)
public static object luaL_checkudata(LuaCore.lua_State luaState, int stackPos, string meta)
{
//int p = (int)LuaCore.lua_touserdata2(luaState, ud);
int p = fourBytesToInt(LuaCore.lua_touserdata(luaState, ud) as byte[]);
Console.WriteLine("asddddd:" + p.ToString());
return LuaCore.luaL_checkudata(luaState, stackPos, meta);
}
if(p != 0)
public static bool luaL_getmetafield(LuaCore.lua_State luaState, int stackPos, string field)
{
return LuaCore.luaL_getmetafield(luaState, stackPos, field) != 0;
}
public static int luaL_loadbuffer(LuaCore.lua_State luaState, string buff, string name)
{
return LuaCore.luaL_loadbuffer(luaState, buff, (uint)buff.Length, name);
}
public static int luaL_loadfile(LuaCore.lua_State luaState, string filename)
{
return LuaCore.luaL_loadfile(luaState, filename);
}
public static void lua_error(LuaCore.lua_State luaState)
{
LuaCore.lua_error(luaState);
}
public static bool lua_checkstack(LuaCore.lua_State luaState,int extra)
{
return LuaCore.lua_checkstack(luaState, extra) != 0;
}
public static int lua_next(LuaCore.lua_State luaState,int index)
{
return LuaCore.lua_next(luaState, index);
}
public static void lua_pushlightuserdata(LuaCore.lua_State luaState, object udata)
{
LuaCore.lua_pushlightuserdata(luaState, udata);
}
public static int luanet_rawnetobj(LuaCore.lua_State luaState,int obj)
{
byte[] bytes = lua_touserdata(luaState, obj) as byte[];
return fourBytesToInt(bytes);
}
// Starting with 5.1 the auxlib version of checkudata throws an exception if the type isn't right
// Instead, we want to run our own version that checks the type and just returns null for failure
private static object checkudata_raw(LuaCore.lua_State L, int ud, string tname)
{
object p = LuaCore.lua_touserdata(L, ud);
if(p != null)
{
/* value is a userdata? */
if(LuaCore.lua_getmetatable(luaState, ud) != 0)
if(LuaCore.lua_getmetatable(L, ud) != 0)
{
bool isEqual;
/* does it have a metatable? */
LuaCore.lua_getfield(luaState, (int)PseudoIndex.Registry, tname); /* get correct metatable */
Console.Write("valami:");
Console.Write(LuaCore.lua_rawequal(luaState, -1, -2) != 0);
Console.Write("\n");
Console.Write("valami2:");
Console.Write(LuaCore.lua_rawequal(luaState, -1, -2).ToBoolean());
Console.Write("\n");
bool isEqual = LuaCore.lua_rawequal(luaState, -1, -2).ToBoolean();
LuaCore.lua_getfield(L, (int)LuaIndexes.Registry, tname); /* get correct metatable */
isEqual = LuaCore.lua_rawequal(L, -1, -2) != 0;
// NASTY - we need our own version of the lua_pop macro
// lua_pop(L, 2); /* remove both metatables */
LuaCore.lua_settop(luaState, -(2) - 1);
LuaCore.lua_settop(L, -(2) - 1);
if(isEqual) /* does it have the correct mt? */
return p;
}
}
return 0;
return null;
}
public static int luanet_checkudata(LuaCore.lua_State luaState, int ud, string tname)
{
int udata = checkudata_raw(luaState, ud, tname);
return udata != 0 ? udata : -1;
object udata = checkudata_raw(luaState, ud, tname);
return !udata.IsNull() ? fourBytesToInt(udata as byte[]) : -1;
}
public static bool luaL_checkmetatable(LuaCore.lua_State luaState,int index)
{
bool retVal = false;
if(lua_getmetatable(luaState, index) != 0)
{
lua_pushlightuserdata(luaState, tag);
lua_rawget(luaState, -2);
retVal = !lua_isnil(luaState, -1);
lua_settop(luaState, -3);
}
return retVal;
}
public static object luanet_gettag()
{
return tag;
}
public static void luanet_newudata(LuaCore.lua_State luaState, int val)
public static void luanet_newudata(LuaCore.lua_State luaState,int val)
{
//LuaCore.lua_newuserdata(luaState, (uint)val);
byte[] userdata = LuaCore.lua_newuserdata(luaState, sizeof(int)) as byte[];
var userdata = lua_newuserdata(luaState, sizeof(int)) as byte[];
intToFourBytes(val, userdata);
}
public static int luanet_tonetobject(LuaCore.lua_State luaState, int index)
public static int luanet_tonetobject(LuaCore.lua_State luaState,int index)
{
int udata;
Console.WriteLine("x" + LuaCore.lua_type(luaState, index).ToString());
byte[] udata;
if(LuaCore.lua_type(luaState, index).ToLuaTypes() == LuaTypes.UserData)
if(lua_type(luaState, index) == LuaTypes.UserData)
{
if(luaL_checkmetatable(luaState, index))
{
udata = fourBytesToInt(LuaCore.lua_touserdata(luaState, index) as byte[]);
if(udata != 0)
return udata;
udata=lua_touserdata(luaState, index) as byte[];
if(!udata.IsNull())
return fourBytesToInt(udata);
}
udata = checkudata_raw(luaState, index, "luaNet_class");
if(udata != 0)
return udata;
udata = checkudata_raw(luaState, index, "luaNet_class") as byte[];
if(!udata.IsNull())
return fourBytesToInt(udata);
udata = checkudata_raw(luaState, index, "luaNet_searchbase");
if(udata != 0)
return udata;
udata = checkudata_raw(luaState, index, "luaNet_searchbase") as byte[];
if(!udata.IsNull())
return fourBytesToInt(udata);
udata = checkudata_raw(luaState, index, "luaNet_function");
if(udata != 0)
return udata;
udata = checkudata_raw(luaState, index, "luaNet_function") as byte[];
if(!udata.IsNull())
return fourBytesToInt(udata);
}
return -1;
}
public static int lua_ref(LuaCore.lua_State luaState, int lockRef)
{
return lockRef != 0 ? LuaCore.luaL_ref(luaState, (int)PseudoIndex.Registry) : 0;
}
private static int fourBytesToInt(byte[] bytes)
{
Console.WriteLine("tömb:" + bytes.Length.ToString());
return bytes[0] + (bytes[1] << 8) + (bytes[2] << 16) + (bytes[3] << 24);
}
......@@ -248,6 +533,5 @@ namespace LuaInterface
bytes[2] = (byte)(val >> 16);
bytes[3] = (byte)(val >> 24);
}
#endregion
}
}
\ No newline at end of file
......@@ -90,7 +90,7 @@ namespace LuaInterface
private int runFunctionDelegate(LuaCore.lua_State luaState)
{
LuaCore.lua_CFunction func = (LuaCore.lua_CFunction)translator.getRawNetObject(luaState, 1);
LuaCore.lua_remove(luaState, 1);
LuaLib.lua_remove(luaState, 1);
return func(luaState);
}
......@@ -121,7 +121,7 @@ namespace LuaInterface
if(!obj.IsNull())
translator.push(luaState, obj.ToString() + ": " + obj.GetHashCode());
else
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
......@@ -133,15 +133,15 @@ namespace LuaInterface
/// FIXME, move somewhere else
public static void dumpStack(ObjectTranslator translator, LuaCore.lua_State luaState)
{
int depth = LuaCore.lua_gettop(luaState);
int depth = LuaLib.lua_gettop(luaState);
Debug.WriteLine("lua stack depth: " + depth);
for(int i = 1; i <= depth; i++)
{
var type = LuaCore.lua_type(luaState, i).ToLuaTypes();
var type = LuaLib.lua_type(luaState, i);
// 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.Table) ? "table" : LuaCore.lua_typename(luaState, (int)type).ToString();
string strrep = LuaCore.lua_tostring(luaState, i).ToString();
string typestr = (type == LuaTypes.Table) ? "table" : LuaLib.lua_typename(luaState, type);
string strrep = LuaLib.lua_tostring(luaState, i).ToString();
if(type == LuaTypes.UserData)
{
......@@ -167,7 +167,7 @@ namespace LuaInterface
if(obj.IsNull())
{
translator.throwError(luaState, "trying to index an invalid object reference");
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
......@@ -234,7 +234,7 @@ namespace LuaInterface
if(actualParms.IsNull() || actualParms.Length != 1)
{
translator.throwError(luaState, "method not found (or no indexer): " + index);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
else
{
......@@ -258,7 +258,7 @@ namespace LuaInterface
else
translator.throwError(luaState, "exception indexing '" + index + "' " + e.Message);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
}
}
......@@ -266,7 +266,7 @@ namespace LuaInterface
}
}
LuaCore.lua_pushboolean(luaState, 0);
LuaLib.lua_pushboolean(luaState, false);
return 2;
}
......@@ -281,30 +281,30 @@ namespace LuaInterface
if(obj.IsNull())
{
translator.throwError(luaState, "trying to index an invalid object reference");
LuaCore.lua_pushnil(luaState);
LuaCore.lua_pushboolean(luaState, 0);
LuaLib.lua_pushnil(luaState);
LuaLib.lua_pushboolean(luaState, false);
return 2;
}
string methodName = LuaCore.lua_tostring(luaState, 2).ToString();
string methodName = LuaLib.lua_tostring(luaState, 2).ToString();
if(methodName.IsNull())
{
LuaCore.lua_pushnil(luaState);
LuaCore.lua_pushboolean(luaState, 0);
LuaLib.lua_pushnil(luaState);
LuaLib.lua_pushboolean(luaState, false);
return 2;
}
getMember(luaState, obj.GetType(), obj, "__luaInterface_base_" + methodName, BindingFlags.Instance | BindingFlags.IgnoreCase);
LuaCore.lua_settop(luaState, -2);
LuaLib.lua_settop(luaState, -2);
if(LuaCore.lua_type(luaState, -1).ToLuaTypes() == LuaTypes.Nil)
if(LuaLib.lua_type(luaState, -1) == LuaTypes.Nil)
{
LuaCore.lua_settop(luaState, -2);
LuaLib.lua_settop(luaState, -2);
return getMember(luaState, obj.GetType(), obj, methodName, BindingFlags.Instance | BindingFlags.IgnoreCase);
}
LuaCore.lua_pushboolean(luaState, 0);
LuaLib.lua_pushboolean(luaState, false);
return 2;
}
......@@ -384,7 +384,7 @@ namespace LuaInterface
}
catch
{
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
}
else if(member.MemberType == MemberTypes.Property)
......@@ -405,12 +405,12 @@ namespace LuaInterface
if(objType is Type && !(((Type)objType) == typeof(object)))
return getMember(luaState, ((Type)objType).BaseType, obj, methodName, bindingType);
else
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
catch(TargetInvocationException e) // Convert this exception into a Lua error
{
ThrowError(luaState, e);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
}
else if(member.MemberType == MemberTypes.Event)
......@@ -456,7 +456,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
translator.throwError(luaState, "can't pass instance to static method " + methodName);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
}
else
......@@ -465,7 +465,7 @@ namespace LuaInterface
// is not sufficient. valid data members may return nil and therefore there must be some
// way to know the member just doesn't exist.
translator.throwError(luaState, "unknown member name " + methodName);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
// push false because we are NOT returning a function (see luaIndexFunction)
......@@ -525,9 +525,9 @@ namespace LuaInterface
// We didn't find a property name, now see if we can use a [] style this accessor to set array contents
try
{
if(type.IsArray && LuaCore.lua_isnumber(luaState, 2).ToBoolean())
if(type.IsArray && LuaLib.lua_isnumber(luaState, 2))
{
int index = (int)LuaCore.lua_tonumber(luaState, 2);
int index = (int)LuaLib.lua_tonumber(luaState, 2);
var arr = (Array)target;
object val = translator.getAsType(luaState, 3, arr.GetType().GetElementType());
arr.SetValue(val, index);
......@@ -586,14 +586,14 @@ namespace LuaInterface
// changing the lua typecode to string
// Note: We don't use isstring because the standard lua C isstring considers either strings or numbers to
// be true for isstring.
if(LuaCore.lua_type(luaState, 2).ToLuaTypes() != LuaTypes.String)
if(LuaLib.lua_type(luaState, 2) != LuaTypes.String)
{
detailMessage = "property names must be strings";
return false;
}
// We only look up property names by string
string fieldName = LuaCore.lua_tostring(luaState, 2).ToString();
string fieldName = LuaLib.lua_tostring(luaState, 2).ToString();
if(fieldName.IsNull() || fieldName.Length < 1 || !(char.IsLetter(fieldName[0]) || fieldName[0] == '_'))
{
detailMessage = "invalid property name";
......@@ -700,25 +700,25 @@ namespace LuaInterface
if(obj.IsNull() || !(obj is IReflect))
{
translator.throwError(luaState, "trying to index an invalid type reference");
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
else
klass = (IReflect)obj;
if(LuaCore.lua_isnumber(luaState, 2).ToBoolean())
if(LuaLib.lua_isnumber(luaState, 2))
{
int size = (int)LuaCore.lua_tonumber(luaState, 2);
int size = (int)LuaLib.lua_tonumber(luaState, 2);
translator.push(luaState, Array.CreateInstance(klass.UnderlyingSystemType, size));
return 1;
}
else
{
string methodName = LuaCore.lua_tostring(luaState, 2).ToString();
string methodName = LuaLib.lua_tostring(luaState, 2).ToString();
if(methodName.IsNull())
{
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
} //CP: Ignore case
else
......@@ -760,13 +760,13 @@ namespace LuaInterface
if(obj.IsNull() || !(obj is IReflect))
{
translator.throwError(luaState, "trying to call constructor on an invalid type reference");
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
else
klass = (IReflect)obj;
LuaCore.lua_remove(luaState, 1);
LuaLib.lua_remove(luaState, 1);
var constructors = klass.UnderlyingSystemType.GetConstructors();
foreach(var constructor in constructors)
......@@ -782,11 +782,11 @@ namespace LuaInterface
catch(TargetInvocationException e)
{
ThrowError(luaState, e);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
catch
{
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
}
return 1;
......@@ -796,7 +796,7 @@ namespace LuaInterface
string constructorName = (constructors.Length == 0) ? "unknown" : constructors[0].Name;
translator.throwError(luaState, String.Format("{0} does not contain constructor({1}) argument match",
klass.UnderlyingSystemType, constructorName));
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
......@@ -811,7 +811,7 @@ namespace LuaInterface
bool isMethod = true;
var paramInfo = method.GetParameters();
int currentLuaParam = 1;
int nLuaParams = LuaCore.lua_gettop(luaState);
int nLuaParams = LuaLib.lua_gettop(luaState);
var paramList = new ArrayList();
var outList = new List<int>();
var argTypes = new List<MethodArgs>();
......@@ -933,7 +933,7 @@ namespace LuaInterface
try
{
luaType = LuaCore.lua_type(luaState, currentLuaParam).ToLuaTypes();
luaType = LuaLib.lua_type(luaState, currentLuaParam);
}
catch(Exception ex)
{
......
......@@ -115,7 +115,7 @@ namespace LuaInterface.Method
bool failedCall = true;
int nReturnValues = 0;
if(!LuaCore.lua_checkstack(luaState, 5).ToBoolean())
if(!LuaLib.lua_checkstack(luaState, 5))
throw new LuaException("Lua stack overflow");
bool isStatic = (_BindingType & BindingFlags.Static) == BindingFlags.Static;
......@@ -128,15 +128,15 @@ namespace LuaInterface.Method
else
targetObject = _ExtractTarget(luaState, 1);
//LuaCore.lua_remove(luaState,1); // Pops the receiver
//LuaLib.lua_remove(luaState,1); // Pops the receiver
if(!_LastCalledMethod.cachedMethod.IsNull()) // 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 numArgsPassed = LuaCore.lua_gettop(luaState) - numStackToSkip;
int numArgsPassed = LuaLib.lua_gettop(luaState) - numStackToSkip;
if(numArgsPassed == _LastCalledMethod.argTypes.Length) // No. of args match?
{
if(!LuaCore.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6).ToBoolean())
if(!LuaLib.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6))
throw new LuaException("Lua stack overflow");
try
......@@ -172,7 +172,7 @@ namespace LuaInterface.Method
}
if(_LastCalledMethod.args[_LastCalledMethod.argTypes[i].index] == null &&
!LuaCore.lua_isnil(luaState, i + 1 + numStackToSkip))
!LuaLib.lua_isnil(luaState, i + 1 + numStackToSkip))
throw new LuaException("argument number " + (i + 1) + " is invalid");
}
......@@ -212,11 +212,11 @@ namespace LuaInterface.Method
if(targetObject.IsNull())
{
_Translator.throwError(luaState, String.Format("instance method '{0}' requires a non null target object", _MethodName));
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
LuaCore.lua_remove(luaState, 1); // Pops the receiver
LuaLib.lua_remove(luaState, 1); // Pops the receiver
}
bool hasMatch = false;
......@@ -239,7 +239,7 @@ namespace LuaInterface.Method
{
string msg = (candidateName == null) ? "invalid arguments to method call" : ("invalid arguments to method: " + candidateName);
_Translator.throwError(luaState, msg);
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
}
......@@ -265,7 +265,7 @@ namespace LuaInterface.Method
else if(methodToCall.ContainsGenericParameters)
{
_Translator.throwError(luaState, "unable to invoke method on generic class as the current method is an open generic method");
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
}
......@@ -274,13 +274,13 @@ namespace LuaInterface.Method
if(!methodToCall.IsStatic && !methodToCall.IsConstructor && targetObject == null)
{
targetObject = _ExtractTarget(luaState, 1);
LuaCore.lua_remove(luaState, 1); // Pops the receiver
LuaLib.lua_remove(luaState, 1); // Pops the receiver
}
if(!_Translator.matchParameters(luaState, methodToCall, ref _LastCalledMethod))
{
_Translator.throwError(luaState, "invalid arguments to method call");
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
}
......@@ -288,7 +288,7 @@ namespace LuaInterface.Method
if(failedCall)
{
if(!LuaCore.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6).ToBoolean())
if(!LuaLib.lua_checkstack(luaState, _LastCalledMethod.outList.Length + 6))
throw new LuaException("Lua stack overflow");
try
......
......@@ -31,7 +31,8 @@ using System.Collections;
using System.Collections.Generic;
using LuaInterface.Method;
using LuaInterface.Exceptions;
// TODO: Kódot átt kell alakítani a többihez hasonlóan.
using LuaInterface.Extensions;
namespace LuaInterface
{
using LuaCore = KopiLua.Lua;
......@@ -44,33 +45,35 @@ namespace LuaInterface
*/
public class ObjectTranslator
{
internal CheckType typeChecker;
// object # to object (FIXME - it should be possible to get object address as an object #)
public readonly Dictionary<int, object> objects = new Dictionary<int, object>();
private LuaCore.lua_CFunction registerTableFunction, unregisterTableFunction, getMethodSigFunction,
getConstructorSigFunction, importTypeFunction, loadAssemblyFunction;
// object to object #
public readonly Dictionary<object, int> objectsBackMap = new Dictionary<object, int>();
internal Lua interpreter;
// object # to object (FIXME - it should be possible to get object address as an object #)
public readonly Dictionary<int, object> objects = new Dictionary<int, object>();
internal EventHandlerContainer pendingEvents = new EventHandlerContainer();
private MetaFunctions metaFunctions;
private List<Assembly> assemblies;
private LuaCore.lua_CFunction registerTableFunction,unregisterTableFunction,getMethodSigFunction,
getConstructorSigFunction,importTypeFunction,loadAssemblyFunction;
internal EventHandlerContainer pendingEvents = new EventHandlerContainer();
internal CheckType typeChecker;
internal Lua interpreter;
/// <summary>
/// We want to ensure that objects always have a unique ID
/// </summary>
private int nextObj = 0;
public ObjectTranslator(Lua interpreter,LuaCore.lua_State luaState)
public ObjectTranslator(Lua interpreter, LuaCore.lua_State luaState)
{
this.interpreter=interpreter;
typeChecker=new CheckType(this);
metaFunctions=new MetaFunctions(this);
assemblies=new List<Assembly>();
this.interpreter = interpreter;
typeChecker = new CheckType(this);
metaFunctions = new MetaFunctions(this);
assemblies = new List<Assembly>();
importTypeFunction=new LuaCore.lua_CFunction(this.importType);
loadAssemblyFunction=new LuaCore.lua_CFunction(this.loadAssembly);
registerTableFunction=new LuaCore.lua_CFunction(this.registerTable);
unregisterTableFunction=new LuaCore.lua_CFunction(this.unregisterTable);
getMethodSigFunction=new LuaCore.lua_CFunction(this.getMethodSignature);
getConstructorSigFunction=new LuaCore.lua_CFunction(this.getConstructorSignature);
importTypeFunction = new LuaCore.lua_CFunction(this.importType);
loadAssemblyFunction = new LuaCore.lua_CFunction(this.loadAssembly);
registerTableFunction = new LuaCore.lua_CFunction(this.registerTable);
unregisterTableFunction = new LuaCore.lua_CFunction(this.unregisterTable);
getMethodSigFunction = new LuaCore.lua_CFunction(this.getMethodSignature);
getConstructorSigFunction = new LuaCore.lua_CFunction(this.getConstructorSignature);
createLuaObjectList(luaState);
createIndexingMetaFunction(luaState);
......@@ -85,132 +88,141 @@ namespace LuaInterface
*/
private void createLuaObjectList(LuaCore.lua_State luaState)
{
LuaCore.lua_pushstring(luaState,"luaNet_objects");
LuaCore.lua_newtable(luaState);
LuaCore.lua_newtable(luaState);
LuaCore.lua_pushstring(luaState,"__mode");
LuaCore.lua_pushstring(luaState,"v");
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_setmetatable(luaState,-2);
LuaCore.lua_settable(luaState, (int) PseudoIndex.Registry);
LuaLib.lua_pushstring(luaState, "luaNet_objects");
LuaLib.lua_newtable(luaState);
LuaLib.lua_newtable(luaState);
LuaLib.lua_pushstring(luaState, "__mode");
LuaLib.lua_pushstring(luaState, "v");
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_setmetatable(luaState, -2);
LuaLib.lua_settable(luaState, (int)LuaIndexes.Registry);
}
/*
* Registers the indexing function of CLR objects
* passed to Lua
*/
private void createIndexingMetaFunction(LuaCore.lua_State luaState)
{
LuaCore.lua_pushstring(luaState,"luaNet_indexfunction");
LuaLib.luaL_dostring(luaState,MetaFunctions.luaIndexFunction); // steffenj: lua_dostring renamed to luaL_dostring
//LuaLib.lua_pushstdcallcfunction(luaState,indexFunction);
LuaCore.lua_rawset(luaState, (int) PseudoIndex.Registry);
LuaLib.lua_pushstring(luaState, "luaNet_indexfunction");
LuaLib.luaL_dostring(luaState, MetaFunctions.luaIndexFunction); // steffenj: lua_dostring renamed to luaL_dostring
//LuaLib.lua_pushstdcallcfunction(luaState, indexFunction);
LuaLib.lua_rawset(luaState, (int)LuaIndexes.Registry);
}
/*
* Creates the metatable for superclasses (the base
* field of registered tables)
*/
private void createBaseClassMetatable(LuaCore.lua_State luaState)
{
LuaCore.luaL_newmetatable(luaState,"luaNet_searchbase");
LuaCore.lua_pushstring(luaState,"__gc");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__tostring");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__index");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.baseIndexFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__newindex");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.newindexFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_settop(luaState,-2);
LuaLib.luaL_newmetatable(luaState, "luaNet_searchbase");
LuaLib.lua_pushstring(luaState, "__gc");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__tostring");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__index");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.baseIndexFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__newindex");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_settop(luaState, -2);
}
/*
* Creates the metatable for type references
*/
private void createClassMetatable(LuaCore.lua_State luaState)
{
LuaCore.luaL_newmetatable(luaState,"luaNet_class");
LuaCore.lua_pushstring(luaState,"__gc");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__tostring");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__index");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.classIndexFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__newindex");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.classNewindexFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__call");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.callConstructorFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_settop(luaState,-2);
LuaLib.luaL_newmetatable(luaState, "luaNet_class");
LuaLib.lua_pushstring(luaState, "__gc");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__tostring");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__index");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.classIndexFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__newindex");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.classNewindexFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__call");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.callConstructorFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_settop(luaState, -2);
}
/*
* Registers the global functions used by LuaInterface
*/
private void setGlobalFunctions(LuaCore.lua_State luaState)
{
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.indexFunction);
LuaCore.lua_setglobal(luaState,"get_object_member");
LuaLib.lua_pushstdcallcfunction(luaState,importTypeFunction);
LuaCore.lua_setglobal(luaState,"import_type");
LuaLib.lua_pushstdcallcfunction(luaState,loadAssemblyFunction);
LuaCore.lua_setglobal(luaState,"load_assembly");
LuaLib.lua_pushstdcallcfunction(luaState,registerTableFunction);
LuaCore.lua_setglobal(luaState,"make_object");
LuaLib.lua_pushstdcallcfunction(luaState,unregisterTableFunction);
LuaCore.lua_setglobal(luaState,"free_object");
LuaLib.lua_pushstdcallcfunction(luaState,getMethodSigFunction);
LuaCore.lua_setglobal(luaState,"get_method_bysig");
LuaLib.lua_pushstdcallcfunction(luaState,getConstructorSigFunction);
LuaCore.lua_setglobal(luaState,"get_constructor_bysig");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.indexFunction);
LuaLib.lua_setglobal(luaState, "get_object_member");
LuaLib.lua_pushstdcallcfunction(luaState, importTypeFunction);
LuaLib.lua_setglobal(luaState, "import_type");
LuaLib.lua_pushstdcallcfunction(luaState, loadAssemblyFunction);
LuaLib.lua_setglobal(luaState, "load_assembly");
LuaLib.lua_pushstdcallcfunction(luaState, registerTableFunction);
LuaLib.lua_setglobal(luaState, "make_object");
LuaLib.lua_pushstdcallcfunction(luaState, unregisterTableFunction);
LuaLib.lua_setglobal(luaState, "free_object");
LuaLib.lua_pushstdcallcfunction(luaState, getMethodSigFunction);
LuaLib.lua_setglobal(luaState, "get_method_bysig");
LuaLib.lua_pushstdcallcfunction(luaState, getConstructorSigFunction);
LuaLib.lua_setglobal(luaState, "get_constructor_bysig");
}
/*
* Creates the metatable for delegates
*/
private void createFunctionMetatable(LuaCore.lua_State luaState)
{
LuaCore.luaL_newmetatable(luaState,"luaNet_function");
LuaCore.lua_pushstring(luaState,"__gc");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_pushstring(luaState,"__call");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.execDelegateFunction);
LuaCore.lua_settable(luaState,-3);
LuaCore.lua_settop(luaState,-2);
LuaLib.luaL_newmetatable(luaState, "luaNet_function");
LuaLib.lua_pushstring(luaState, "__gc");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__call");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.execDelegateFunction);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_settop(luaState, -2);
}
/*
* Passes errors (argument e) to the Lua interpreter
*/
internal void throwError(LuaCore.lua_State luaState, object e)
{
// We use this to remove anything pushed by luaL_where
int oldTop = LuaCore.lua_gettop(luaState);
int oldTop = LuaLib.lua_gettop(luaState);
// 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
LuaCore.luaL_where(luaState, 1);
object[] curlev = popValues(luaState, oldTop);
LuaLib.luaL_where(luaState, 1);
var curlev = popValues(luaState, oldTop);
// Determine the position in the script where the exception was triggered
string errLocation = "";
if (curlev.Length > 0)
string errLocation = string.Empty;
if(curlev.Length > 0)
errLocation = curlev[0].ToString();
string message = e as string;
if (message != null)
if(!message.IsNull())
{
// Wrap Lua error (just a string) and store the error location
e = new LuaScriptException(message, errLocation);
}
else
{
Exception ex = e as Exception;
if (ex != null)
var ex = e as Exception;
if(!ex.IsNull())
{
// Wrap generic .NET exception as an InnerException and store the error location
e = new LuaScriptException(ex, errLocation);
......@@ -218,8 +230,9 @@ namespace LuaInterface
}
push(luaState, e);
LuaCore.lua_error(luaState);
LuaLib.lua_error(luaState);
}
/*
* Implementation of load_assembly. Throws an error
* if the assembly is not found.
......@@ -228,32 +241,27 @@ namespace LuaInterface
{
try
{
string assemblyName=LuaCore.lua_tostring(luaState,1).ToString();
string assemblyName = LuaLib.lua_tostring(luaState, 1).ToString();
Assembly assembly = null;
try
{
assembly = Assembly.Load(assemblyName);
}
catch (BadImageFormatException)
catch(BadImageFormatException)
{
// The assemblyName was invalid. It is most likely a path.
}
if (assembly == null)
{
if(assembly.IsNull())
assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyName));
}
if (assembly != null && !assemblies.Contains(assembly))
{
if(!assembly.IsNull() && !assemblies.Contains(assembly))
assemblies.Add(assembly);
}
}
catch(Exception e)
{
throwError(luaState,e);
throwError(luaState, e);
}
return 0;
......@@ -261,14 +269,13 @@ namespace LuaInterface
internal Type FindType(string className)
{
foreach(Assembly assembly in assemblies)
{
Type klass=assembly.GetType(className);
if(klass!=null)
foreach(var assembly in assemblies)
{
var klass = assembly.GetType(className);
if(!klass.IsNull())
return klass;
}
}
return null;
}
......@@ -278,14 +285,17 @@ namespace LuaInterface
*/
private int importType(LuaCore.lua_State luaState)
{
string className=LuaCore.lua_tostring(luaState,1).ToString();
Type klass=FindType(className);
if(klass!=null)
pushType(luaState,klass);
string className = LuaLib.lua_tostring(luaState, 1).ToString();
var klass = FindType(className);
if(!klass.IsNull())
pushType(luaState, klass);
else
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return 1;
}
/*
* Implementation of make_object. Registers a table (first
* argument in the stack) as an object subclassing the
......@@ -293,33 +303,35 @@ namespace LuaInterface
*/
private int registerTable(LuaCore.lua_State luaState)
{
if(LuaCore.lua_type(luaState,1).ToLuaTypes()==LuaTypes.Table)
if(LuaLib.lua_type(luaState, 1) == LuaTypes.Table)
{
LuaTable luaTable=getTable(luaState,1);
string superclassName = LuaCore.lua_tostring(luaState, 2).ToString();
if (superclassName != null)
var luaTable = getTable(luaState, 1);
string superclassName = LuaLib.lua_tostring(luaState, 2).ToString();
if(!superclassName.IsNull())
{
Type klass = FindType(superclassName);
if (klass != null)
var klass = FindType(superclassName);
if(!klass.IsNull())
{
// Creates and pushes the object in the stack, setting
// it as the metatable of the first argument
object obj = CodeGeneration.Instance.GetClassInstance(klass, luaTable);
pushObject(luaState, obj, "luaNet_metatable");
LuaCore.lua_newtable(luaState);
LuaCore.lua_pushstring(luaState, "__index");
LuaCore.lua_pushvalue(luaState, -3);
LuaCore.lua_settable(luaState, -3);
LuaCore.lua_pushstring(luaState, "__newindex");
LuaCore.lua_pushvalue(luaState, -3);
LuaCore.lua_settable(luaState, -3);
LuaCore.lua_setmetatable(luaState, 1);
LuaLib.lua_newtable(luaState);
LuaLib.lua_pushstring(luaState, "__index");
LuaLib.lua_pushvalue(luaState, -3);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_pushstring(luaState, "__newindex");
LuaLib.lua_pushvalue(luaState, -3);
LuaLib.lua_settable(luaState, -3);
LuaLib.lua_setmetatable(luaState, 1);
// Pushes the object again, this time as the base field
// of the table and with the luaNet_searchbase metatable
LuaCore.lua_pushstring(luaState, "base");
LuaLib.lua_pushstring(luaState, "base");
int index = addObject(obj);
pushNewObject(luaState, obj, index, "luaNet_searchbase");
LuaCore.lua_rawset(luaState, 1);
LuaLib.lua_rawset(luaState, 1);
}
else
throwError(luaState, "register_table: can not find superclass '" + superclassName + "'");
......@@ -327,9 +339,12 @@ namespace LuaInterface
else
throwError(luaState, "register_table: superclass name can not be null");
}
else throwError(luaState,"register_table: first arg is not a table");
else
throwError(luaState, "register_table: first arg is not a table");
return 0;
}
/*
* Implementation of free_object. Clears the metatable and the
* base field, freeing the created object for garbage-collection
......@@ -338,116 +353,139 @@ namespace LuaInterface
{
try
{
if(LuaCore.lua_getmetatable(luaState,1)!=0)
if(LuaLib.lua_getmetatable(luaState, 1) != 0)
{
LuaCore.lua_pushstring(luaState,"__index");
LuaCore.lua_gettable(luaState,-2);
object obj=getRawNetObject(luaState,-1);
if(obj==null) throwError(luaState,"unregister_table: arg is not valid table");
FieldInfo luaTableField=obj.GetType().GetField("__luaInterface_luaTable");
if(luaTableField==null) throwError(luaState,"unregister_table: arg is not valid table");
luaTableField.SetValue(obj,null);
LuaCore.lua_pushnil(luaState);
LuaCore.lua_setmetatable(luaState,1);
LuaCore.lua_pushstring(luaState,"base");
LuaCore.lua_pushnil(luaState);
LuaCore.lua_settable(luaState,1);
LuaLib.lua_pushstring(luaState, "__index");
LuaLib.lua_gettable(luaState, -2);
object obj = getRawNetObject(luaState, -1);
if(obj.IsNull())
throwError(luaState, "unregister_table: arg is not valid table");
var luaTableField = obj.GetType().GetField("__luaInterface_luaTable");
if(luaTableField.IsNull())
throwError(luaState, "unregister_table: arg is not valid table");
luaTableField.SetValue(obj, null);
LuaLib.lua_pushnil(luaState);
LuaLib.lua_setmetatable(luaState, 1);
LuaLib.lua_pushstring(luaState, "base");
LuaLib.lua_pushnil(luaState);
LuaLib.lua_settable(luaState, 1);
}
else throwError(luaState,"unregister_table: arg is not valid table");
else
throwError(luaState, "unregister_table: arg is not valid table");
}
catch(Exception e)
{
throwError(luaState,e.Message);
throwError(luaState, e.Message);
}
return 0;
}
/*
* Implementation of get_method_bysig. Returns nil
* if no matching method is not found.
*/
private int getMethodSignature(LuaCore.lua_State luaState)
{
IReflect klass; object target;
int udata=LuaLib.luanet_checkudata(luaState,1,"luaNet_class");
if(udata!=-1)
IReflect klass;
object target;
int udata = LuaLib.luanet_checkudata(luaState, 1, "luaNet_class");
if(udata != -1)
{
klass=(IReflect)objects[udata];
target=null;
klass = (IReflect)objects[udata];
target = null;
}
else
{
target=getRawNetObject(luaState,1);
if(target==null)
target = getRawNetObject(luaState, 1);
if(target.IsNull())
{
throwError(luaState,"get_method_bysig: first arg is not type or object reference");
LuaCore.lua_pushnil(luaState);
throwError(luaState, "get_method_bysig: first arg is not type or object reference");
LuaLib.lua_pushnil(luaState);
return 1;
}
klass=target.GetType();
klass = target.GetType();
}
string methodName=LuaCore.lua_tostring(luaState,2).ToString();
Type[] signature=new Type[LuaCore.lua_gettop(luaState)-2];
for(int i=0;i<signature.Length;i++)
signature[i]=FindType(LuaCore.lua_tostring(luaState,i+3).ToString());
string methodName = LuaLib.lua_tostring(luaState, 2).ToString();
var signature = new Type[LuaLib.lua_gettop(luaState)-2];
for(int i = 0; i < signature.Length; i++)
signature[i] = FindType(LuaLib.lua_tostring(luaState, i+3).ToString());
try
{
//CP: Added ignore case
MethodInfo method=klass.GetMethod(methodName,BindingFlags.Public | BindingFlags.Static |
var method = klass.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static |
BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.IgnoreCase, null, signature, null);
pushFunction(luaState,new LuaCore.lua_CFunction((new LuaMethodWrapper(this,target,klass,method)).call));
pushFunction(luaState, new LuaCore.lua_CFunction((new LuaMethodWrapper(this, target, klass, method)).call));
}
catch(Exception e)
{
throwError(luaState,e);
LuaCore.lua_pushnil(luaState);
throwError(luaState, e);
LuaLib.lua_pushnil(luaState);
}
return 1;
}
/*
* Implementation of get_constructor_bysig. Returns nil
* if no matching constructor is found.
*/
private int getConstructorSignature(LuaCore.lua_State luaState)
{
IReflect klass=null;
int udata=LuaLib.luanet_checkudata(luaState,1,"luaNet_class");
if(udata!=-1)
{
klass=(IReflect)objects[udata];
}
if(klass==null)
{
throwError(luaState,"get_constructor_bysig: first arg is invalid type reference");
}
Type[] signature=new Type[LuaCore.lua_gettop(luaState)-1];
for(int i=0;i<signature.Length;i++)
signature[i]=FindType(LuaCore.lua_tostring(luaState,i+2).ToString());
IReflect klass = null;
int udata = LuaLib.luanet_checkudata(luaState, 1, "luaNet_class");
if(udata != -1)
klass = (IReflect)objects[udata];
if(klass.IsNull())
throwError(luaState, "get_constructor_bysig: first arg is invalid type reference");
var signature = new Type[LuaLib.lua_gettop(luaState)-1];
for(int i = 0; i < signature.Length; i++)
signature[i] = FindType(LuaLib.lua_tostring(luaState, i+2).ToString());
try
{
ConstructorInfo constructor=klass.UnderlyingSystemType.GetConstructor(signature);
pushFunction(luaState,new LuaCore.lua_CFunction((new LuaMethodWrapper(this,null,klass,constructor)).call));
ConstructorInfo constructor = klass.UnderlyingSystemType.GetConstructor(signature);
pushFunction(luaState, new LuaCore.lua_CFunction((new LuaMethodWrapper(this, null, klass, constructor)).call));
}
catch(Exception e)
{
throwError(luaState,e);
LuaCore.lua_pushnil(luaState);
throwError(luaState, e);
LuaLib.lua_pushnil(luaState);
}
return 1;
}
/*
* Pushes a type reference into the stack
*/
internal void pushType(LuaCore.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
*/
internal void pushFunction(LuaCore.lua_State luaState, LuaCore.lua_CFunction func)
{
pushObject(luaState,func,"luaNet_function");
pushObject(luaState, func, "luaNet_function");
}
/*
* Pushes a CLR object into the Lua stack as an userdata
* with the provided metatable
......@@ -455,330 +493,309 @@ namespace LuaInterface
internal void pushObject(LuaCore.lua_State luaState, object o, string metatable)
{
int index = -1;
// Pushes nil
if(o==null)
if(o.IsNull())
{
LuaCore.lua_pushnil(luaState);
LuaLib.lua_pushnil(luaState);
return;
}
// Object already in the list of Lua objects? Push the stored reference.
bool found = objectsBackMap.TryGetValue(o, out index);
if(found)
{
LuaCore.luaL_getmetatable(luaState,"luaNet_objects");
LuaCore.lua_rawgeti(luaState,-1,index);
LuaLib.luaL_getmetatable(luaState, "luaNet_objects");
LuaLib.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
// 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
// object here
// did we find a non nil object in our table? if not, we need to call collect object
LuaTypes type = LuaCore.lua_type(luaState, -1).ToLuaTypes();
if (type != LuaTypes.Nil)
var type = LuaLib.lua_type(luaState, -1);
if(type != LuaTypes.Nil)
{
LuaCore.lua_remove(luaState, -2); // drop the metatable - we're going to leave our object on the stack
LuaLib.lua_remove(luaState, -2); // drop the metatable - we're going to leave our object on the stack
return;
}
// MetaFunctions.dumpStack(this, luaState);
LuaCore.lua_remove(luaState, -1); // remove the nil object value
LuaCore.lua_remove(luaState, -1); // remove the metatable
LuaLib.lua_remove(luaState, -1); // remove the nil object value
LuaLib.lua_remove(luaState, -1); // remove the metatable
collectObject(o, index); // Remove from both our tables and fall out to get a new ID
}
index = addObject(o);
pushNewObject(luaState,o,index,metatable);
index = addObject(o);
pushNewObject(luaState, o, index, metatable);
}
/*
* Pushes a new object into the Lua stack with the provided
* metatable
*/
private void pushNewObject(LuaCore.lua_State luaState,object o,int index,string metatable)
private void pushNewObject(LuaCore.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
LuaCore.luaL_getmetatable(luaState,o.GetType().AssemblyQualifiedName);
if(LuaCore.lua_isnil(luaState,-1))
{
LuaCore.lua_settop(luaState,-2);
LuaCore.luaL_newmetatable(luaState,o.GetType().AssemblyQualifiedName);
LuaCore.lua_pushstring(luaState,"cache");
LuaCore.lua_newtable(luaState);
LuaCore.lua_rawset(luaState,-3);
LuaCore.lua_pushlightuserdata(luaState,LuaLib.luanet_gettag());
LuaCore.lua_pushnumber(luaState,1);
LuaCore.lua_rawset(luaState,-3);
LuaCore.lua_pushstring(luaState,"__index");
LuaCore.lua_pushstring(luaState,"luaNet_indexfunction");
LuaCore.lua_rawget(luaState, (int) PseudoIndex.Registry);
LuaCore.lua_rawset(luaState,-3);
LuaCore.lua_pushstring(luaState,"__gc");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.gcFunction);
LuaCore.lua_rawset(luaState,-3);
LuaCore.lua_pushstring(luaState,"__tostring");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.toStringFunction);
LuaCore.lua_rawset(luaState,-3);
LuaCore.lua_pushstring(luaState,"__newindex");
LuaLib.lua_pushstdcallcfunction(luaState,metaFunctions.newindexFunction);
LuaCore.lua_rawset(luaState,-3);
LuaLib.luaL_getmetatable(luaState, o.GetType().AssemblyQualifiedName);
if(LuaLib.lua_isnil(luaState, -1))
{
LuaLib.lua_settop(luaState, -2);
LuaLib.luaL_newmetatable(luaState, o.GetType().AssemblyQualifiedName);
LuaLib.lua_pushstring(luaState, "cache");
LuaLib.lua_newtable(luaState);
LuaLib.lua_rawset(luaState, -3);
LuaLib.lua_pushlightuserdata(luaState, LuaLib.luanet_gettag());
LuaLib.lua_pushnumber(luaState, 1);
LuaLib.lua_rawset(luaState, -3);
LuaLib.lua_pushstring(luaState, "__index");
LuaLib.lua_pushstring(luaState, "luaNet_indexfunction");
LuaLib.lua_rawget(luaState, (int)LuaIndexes.Registry);
LuaLib.lua_rawset(luaState, -3);
LuaLib.lua_pushstring(luaState, "__gc");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.gcFunction);
LuaLib.lua_rawset(luaState, -3);
LuaLib.lua_pushstring(luaState, "__tostring");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.toStringFunction);
LuaLib.lua_rawset(luaState, -3);
LuaLib.lua_pushstring(luaState, "__newindex");
LuaLib.lua_pushstdcallcfunction(luaState, metaFunctions.newindexFunction);
LuaLib.lua_rawset(luaState, -3);
}
}
else
{
LuaCore.luaL_getmetatable(luaState,metatable);
}
LuaLib.luaL_getmetatable(luaState, metatable);
// Stores the object index in the Lua list and pushes the
// index into the Lua stack
LuaCore.luaL_getmetatable(luaState,"luaNet_objects");
LuaLib.luanet_newudata(luaState,index);
LuaCore.lua_pushvalue(luaState,-3);
LuaCore.lua_remove(luaState,-4);
LuaCore.lua_setmetatable(luaState,-2);
LuaCore.lua_pushvalue(luaState,-1);
LuaCore.lua_rawseti(luaState,-3,index);
LuaCore.lua_remove(luaState,-2);
LuaLib.luaL_getmetatable(luaState, "luaNet_objects");
LuaLib.luanet_newudata(luaState, index);
LuaLib.lua_pushvalue(luaState, -3);
LuaLib.lua_remove(luaState, -4);
LuaLib.lua_setmetatable(luaState, -2);
LuaLib.lua_pushvalue(luaState, -1);
LuaLib.lua_rawseti(luaState, -3, index);
LuaLib.lua_remove(luaState, -2);
}
/*
* Gets an object from the Lua stack with the desired type, if it matches, otherwise
* returns null.
*/
internal object getAsType(LuaCore.lua_State luaState,int stackPos,Type paramType)
internal object getAsType(LuaCore.lua_State luaState, int stackPos, Type paramType)
{
ExtractValue extractor=typeChecker.checkType(luaState,stackPos,paramType);
if(extractor!=null) return extractor(luaState,stackPos);
return null;
var extractor = typeChecker.checkType(luaState, stackPos, paramType);
return !extractor.IsNull() ? extractor(luaState, stackPos) : null;
}
/// <summary>
/// Given the Lua int ID for an object remove it from our maps
/// </summary>
/// <param name="udata"></param>
/// <param name = "udata"></param>
internal void collectObject(int udata)
{
object o;
bool found = objects.TryGetValue(udata, out o);
// The other variant of collectObject might have gotten here first, in that case we will silently ignore the missing entry
if (found)
if(found)
{
// Debug.WriteLine("Removing " + o.ToString() + " @ " + udata);
objects.Remove(udata);
objectsBackMap.Remove(o);
}
}
/// <summary>
/// Given an object reference, remove it from our maps
/// </summary>
/// <param name="udata"></param>
void collectObject(object o, int udata)
/// <param name = "udata"></param>
private void collectObject(object o, int udata)
{
// Debug.WriteLine("Removing " + o.ToString() + " @ " + udata);
objects.Remove(udata);
objectsBackMap.Remove(o);
}
/// <summary>
/// We want to ensure that objects always have a unique ID
/// </summary>
int nextObj = 0;
int addObject(object obj)
private int addObject(object obj)
{
// New object: inserts it in the list
int index = nextObj++;
// Debug.WriteLine("Adding " + obj.ToString() + " @ " + index);
objects[index] = obj;
objectsBackMap[obj] = index;
return index;
}
/*
* Gets an object from the Lua stack according to its Lua type.
*/
internal object getObject(LuaCore.lua_State luaState,int index)
internal object getObject(LuaCore.lua_State luaState, int index)
{
LuaTypes type=LuaCore.lua_type(luaState,index).ToLuaTypes();
var type = LuaLib.lua_type(luaState, index);
switch(type)
{
case LuaTypes.Number:
{
return LuaCore.lua_tonumber(luaState,index);
return LuaLib.lua_tonumber(luaState, index);
}
case LuaTypes.String:
{
return LuaCore.lua_tostring(luaState,index);
return LuaLib.lua_tostring(luaState, index);
}
case LuaTypes.Boolean:
{
return LuaCore.lua_toboolean(luaState,index);
return LuaLib.lua_toboolean(luaState, index);
}
case LuaTypes.Table:
{
return getTable(luaState,index);
return getTable(luaState, index);
}
case LuaTypes.Function:
{
return getFunction(luaState,index);
return getFunction(luaState, index);
}
case LuaTypes.UserData:
{
int udata=LuaLib.luanet_tonetobject(luaState,index);
Console.WriteLine(udata);
if(udata!=-1)
return objects[udata];
else
return getUserData(luaState,index);
int udata = LuaLib.luanet_tonetobject(luaState, index);
return udata != -1 ? objects[udata] : getUserData(luaState, index);
}
default:
return null;
}
}
/*
* Gets the table in the index positon of the Lua stack.
*/
internal LuaTable getTable(LuaCore.lua_State luaState,int index)
internal LuaTable getTable(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_pushvalue(luaState,index);
return new LuaTable(LuaLib.lua_ref(luaState,1),interpreter);
LuaLib.lua_pushvalue(luaState, index);
return new LuaTable(LuaLib.lua_ref(luaState, 1), interpreter);
}
/*
* Gets the userdata in the index positon of the Lua stack.
*/
internal LuaUserData getUserData(LuaCore.lua_State luaState,int index)
internal LuaUserData getUserData(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_pushvalue(luaState,index);
return new LuaUserData(LuaLib.lua_ref(luaState,1),interpreter);
LuaLib.lua_pushvalue(luaState, index);
return new LuaUserData(LuaLib.lua_ref(luaState, 1), interpreter);
}
/*
* Gets the function in the index positon of the Lua stack.
*/
internal LuaFunction getFunction(LuaCore.lua_State luaState,int index)
internal LuaFunction getFunction(LuaCore.lua_State luaState, int index)
{
LuaCore.lua_pushvalue(luaState,index);
return new LuaFunction(LuaLib.lua_ref(luaState,1),interpreter);
LuaLib.lua_pushvalue(luaState, index);
return new LuaFunction(LuaLib.lua_ref(luaState, 1), interpreter);
}
/*
* Gets the CLR object in the index positon of the Lua stack. Returns
* delegates as Lua functions.
*/
internal object getNetObject(LuaCore.lua_State luaState,int index)
internal object getNetObject(LuaCore.lua_State luaState, int index)
{
int idx=LuaLib.luanet_tonetobject(luaState,index);
if(idx!=-1)
return objects[idx];
else
return null;
int idx = LuaLib.luanet_tonetobject(luaState, index);
return idx != -1 ? objects[idx] : null;
}
/*
* Gets the CLR object in the index positon of the Lua stack. Returns
* delegates as is.
*/
internal object getRawNetObject(LuaCore.lua_State luaState,int index)
internal object getRawNetObject(LuaCore.lua_State luaState, int index)
{
int udata=LuaLib.luanet_rawnetobj(luaState,index);
if(udata!=-1)
{
return objects[udata];
}
return null;
int udata = LuaLib.luanet_rawnetobj(luaState, index);
return udata != -1 ? objects[udata] : null;
}
/*
* Pushes the entire array into the Lua stack and returns the number
* of elements pushed.
*/
internal int returnValues(LuaCore.lua_State luaState, object[] returnValues)
{
if(LuaCore.lua_checkstack(luaState,returnValues.Length+5).ToBoolean())
{
for(int i=0;i<returnValues.Length;i++)
if(LuaLib.lua_checkstack(luaState, returnValues.Length+5))
{
push(luaState,returnValues[i]);
}
for(int i = 0; i < returnValues.Length; i++)
push(luaState, returnValues[i]);
return returnValues.Length;
} else
}
else
return 0;
}
/*
* Gets the values from the provided index to
* the top of the stack and returns them in an array.
*/
internal object[] popValues(LuaCore.lua_State luaState,int oldTop)
{
int newTop=LuaCore.lua_gettop(luaState);
if(oldTop==newTop)
internal object[] popValues(LuaCore.lua_State luaState, int oldTop)
{
int newTop = LuaLib.lua_gettop(luaState);
if(oldTop == newTop)
return null;
}
else
{
ArrayList returnValues=new ArrayList();
for(int i=oldTop+1;i<=newTop;i++)
{
returnValues.Add(getObject(luaState,i));
}
LuaCore.lua_settop(luaState,oldTop);
var returnValues = new ArrayList();
for(int i = oldTop+1; i <= newTop; i++)
returnValues.Add(getObject(luaState, i));
LuaLib.lua_settop(luaState, oldTop);
return returnValues.ToArray();
}
}
/*
* Gets the values from the provided index to
* the top of the stack and returns them in an array, casting
* them to the provided types.
*/
internal object[] popValues(LuaCore.lua_State luaState,int oldTop,Type[] popTypes)
{
int newTop=LuaCore.lua_gettop(luaState);
if(oldTop==newTop)
internal object[] popValues(LuaCore.lua_State luaState, int oldTop, Type[] popTypes)
{
int newTop = LuaLib.lua_gettop(luaState);
if(oldTop == newTop)
return null;
}
else
{
int iTypes;
ArrayList returnValues=new ArrayList();
var returnValues = new ArrayList();
if(popTypes[0] == typeof(void))
iTypes=1;
iTypes = 1;
else
iTypes=0;
for(int i=oldTop+1;i<=newTop;i++)
iTypes = 0;
for(int i = oldTop+1; i <= newTop; i++)
{
returnValues.Add(getAsType(luaState,i,popTypes[iTypes]));
returnValues.Add(getAsType(luaState, i, popTypes[iTypes]));
iTypes++;
}
LuaCore.lua_settop(luaState,oldTop);
LuaLib.lua_settop(luaState, oldTop);
return returnValues.ToArray();
}
}
// kevinh - the following line doesn't work for remoting proxies - they always return a match for 'is'
// else if(o is ILuaGeneratedType)
static bool IsILua(object o)
private static bool IsILua(object o)
{
if(o is ILuaGeneratedType)
{
// Make sure we are _really_ ILuaGenerated
Type typ = o.GetType();
return (typ.GetInterface("ILuaGeneratedType") != null);
var typ = o.GetType();
return (!typ.GetInterface("ILuaGeneratedType").IsNull ());
}
else
return false;
......@@ -789,60 +806,49 @@ namespace LuaInterface
*/
internal void push(LuaCore.lua_State luaState, object o)
{
if(o==null)
{
LuaCore.lua_pushnil(luaState);
}
if(o.IsNull())
LuaLib.lua_pushnil(luaState);
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 ulong || o is decimal || o is double)
{
double d=Convert.ToDouble(o);
LuaCore.lua_pushnumber(luaState,d);
double d = Convert.ToDouble(o);
LuaLib.lua_pushnumber(luaState, d);
}
else if(o is char)
{
double d = (char)o;
LuaCore.lua_pushnumber(luaState,d);
LuaLib.lua_pushnumber(luaState, d);
}
else if(o is string)
{
string str=(string)o;
LuaCore.lua_pushstring(luaState,str);
string str = (string)o;
LuaLib.lua_pushstring(luaState, str);
}
else if(o is bool)
{
bool b=(bool)o;
LuaCore.lua_pushboolean(luaState, (b == true ? 1 : 0));
bool b = (bool)o;
LuaLib.lua_pushboolean(luaState, b);
}
else if(IsILua(o))
{
(((ILuaGeneratedType)o).__luaInterface_getLuaTable()).push(luaState);
}
else if(o is LuaTable)
{
((LuaTable)o).push(luaState);
}
else if(o is LuaCore.lua_CFunction)
{
pushFunction(luaState,(LuaCore.lua_CFunction)o);
}
pushFunction(luaState, (LuaCore.lua_CFunction)o);
else if(o is LuaFunction)
{
((LuaFunction)o).push(luaState);
}
else
{
pushObject(luaState,o,"luaNet_metatable");
}
pushObject(luaState, o, "luaNet_metatable");
}
/*
* Checks if the method matches the arguments in the Lua stack, getting
* the arguments if it does.
*/
internal bool matchParameters(LuaCore.lua_State luaState,MethodBase method,ref MethodCache methodCache)
internal bool matchParameters(LuaCore.lua_State luaState, MethodBase method, ref MethodCache methodCache)
{
return metaFunctions.matchParameters(luaState,method,ref methodCache);
return metaFunctions.matchParameters(luaState, method, ref methodCache);
}
}
}
\ No newline at end of file
......@@ -27,21 +27,18 @@ using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LuaInterface.Config;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle("LuaInterface")]
[assembly: AssemblyDescription("Bridge between the Lua runtime and the CLR")]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif
//[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("LuaInterface")]
[assembly: AssemblyCopyright("Copyright 2003-2008 Fabio Mascarenhas, Kevin Hesterm and 2012 Megax")]
//[assembly: AssemblyTrademark("")]
[assembly: AssemblyDescription(Consts.LuaInterfaceDescription)]
[assembly: AssemblyConfiguration(Consts.LuaInterfaceConfiguration)]
[assembly: AssemblyCompany(Consts.LuaInterfaceCompany)]
[assembly: AssemblyProduct(Consts.LuaInterfaceProduct)]
[assembly: AssemblyCopyright(Consts.LuaInterfaceCopyright)]
[assembly: AssemblyTrademark(Consts.LuaInterfaceTrademark)]
[assembly: CLSCompliant(true)]
......@@ -60,5 +57,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.4")]
[assembly: AssemblyFileVersion("2.0.4.0")]
\ No newline at end of file
[assembly: AssemblyVersion(Consts.LuaInterfaceVersion)]
[assembly: AssemblyFileVersion(Consts.LuaInterfaceFileVersion)]
\ No newline at end of file
......@@ -5,8 +5,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{0E28CF40-4
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestLuaInterface", "Test\TestLuaInterface\TestLuaInterface.csproj", "{AEAB974E-4F69-4840-A2C4-7BC55F7C7C3E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaInterface.Test", "Test\LuaInterface.Test\LuaInterface.Test.csproj", "{F97A7B76-AD92-49F9-B733-F347B7C8439F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Applications", "Applications", "{B13128D8-A4F3-4C53-A4C6-F2EA34F527BD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaRunner", "Applications\LuaRunner\LuaRunner.csproj", "{3CE4CCB6-3465-43E3-B5ED-5FB9B70D20E5}"
......@@ -57,18 +55,9 @@ Global
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|x64.Build.0 = Release|x64
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|x86.ActiveCfg = Release|x86
{F55CABBB-4108-4A39-94E1-581FD46DC021}.Release|x86.Build.0 = Release|x86
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Debug|x64.ActiveCfg = Debug|x64
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Debug|x64.Build.0 = Debug|x64
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Debug|x86.ActiveCfg = Debug|x86
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Debug|x86.Build.0 = Debug|x86
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Release|x64.ActiveCfg = Release|x64
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Release|x64.Build.0 = Release|x64
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Release|x86.ActiveCfg = Release|x86
{F97A7B76-AD92-49F9-B733-F347B7C8439F}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{AEAB974E-4F69-4840-A2C4-7BC55F7C7C3E} = {0E28CF40-4DFA-46FE-95BB-E90648DFE6F5}
{F97A7B76-AD92-49F9-B733-F347B7C8439F} = {0E28CF40-4DFA-46FE-95BB-E90648DFE6F5}
{3CE4CCB6-3465-43E3-B5ED-5FB9B70D20E5} = {B13128D8-A4F3-4C53-A4C6-F2EA34F527BD}
{E8DDBC21-EF74-4ABA-9C49-BFC702BE25D8} = {B8664957-CB71-4F11-A4DB-59E7514BC5F3}
{F55CABBB-4108-4A39-94E1-581FD46DC021} = {B8664957-CB71-4F11-A4DB-59E7514BC5F3}
......
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