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),
......
This diff is collapsed.
......@@ -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
......
This diff is collapsed.
......@@ -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