"vscode:/vscode.git/clone" did not exist on "e72b6eff0884673997d0ca6385169bbd9b31936d"
Commit b7ad3ad6 authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Updated KopiLua hash

Moved luanet functions to KopiLua
parent 5fc72461
Subproject commit fa091a6e786c9665dc3d0f491770fa8576e1cf76 Subproject commit f86c4bf4f9afb2716f80c97c972d6dad24f1cebf
...@@ -33,9 +33,6 @@ namespace LuaInterface ...@@ -33,9 +33,6 @@ namespace LuaInterface
public class LuaLib public class LuaLib
{ {
// Not sure of the purpose of this, but I'm keeping it -kevinh
private static object tag = 0;
// steffenj: BEGIN additional Lua API functions new in Lua 5.1 // steffenj: BEGIN additional Lua API functions new in Lua 5.1
public static int lua_gc (LuaCore.lua_State luaState, GCOptions what, int data) public static int lua_gc (LuaCore.lua_State luaState, GCOptions what, int data)
{ {
...@@ -283,6 +280,11 @@ namespace LuaInterface ...@@ -283,6 +280,11 @@ namespace LuaInterface
LuaCore.lua_call (luaState, nArgs, nResults); LuaCore.lua_call (luaState, nArgs, nResults);
} }
public static void lua_pushstdcallcfunction (LuaCore.lua_State luaState, LuaCore.lua_CFunction function)
{
LuaCore.lua_pushstdcallcfunction (luaState, function);
}
public static int lua_pcall (LuaCore.lua_State luaState, int nArgs, int nResults, int errfunc) public static int lua_pcall (LuaCore.lua_State luaState, int nArgs, int nResults, int errfunc)
{ {
return LuaCore.lua_pcall (luaState, nArgs, nResults, errfunc); return LuaCore.lua_pcall (luaState, nArgs, nResults, errfunc);
...@@ -336,10 +338,6 @@ namespace LuaInterface ...@@ -336,10 +338,6 @@ namespace LuaInterface
LuaCore.lua_atpanic (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)
{
LuaCore.lua_pushcfunction (luaState, function);
}
public static void lua_pushnumber (LuaCore.lua_State luaState, double number) public static void lua_pushnumber (LuaCore.lua_State luaState, double number)
{ {
...@@ -392,130 +390,55 @@ namespace LuaInterface ...@@ -392,130 +390,55 @@ namespace LuaInterface
return LuaCore.luaL_loadfile (luaState, filename); return LuaCore.luaL_loadfile (luaState, filename);
} }
public static void lua_error (LuaCore.lua_State luaState) public static bool luaL_checkmetatable (LuaCore.lua_State luaState, int index)
{
LuaCore.lua_error (luaState);
}
public static bool lua_checkstack (LuaCore.lua_State luaState, int extra)
{ {
return LuaCore.lua_checkstack (luaState, extra) != 0; return LuaCore.luaL_checkmetatable (luaState, index);
} }
public static int lua_next (LuaCore.lua_State luaState, int index) public static int luanet_tonetobject (LuaCore.lua_State luaState, int index)
{ {
return LuaCore.lua_next (luaState, index); return LuaCore.luanet_tonetobject (luaState, index);
} }
public static void lua_pushlightuserdata (LuaCore.lua_State luaState, object udata) public static void luanet_newudata (LuaCore.lua_State luaState, int val)
{ {
LuaCore.lua_pushlightuserdata (luaState, udata); LuaCore.luanet_newudata (luaState, val);
} }
public static int luanet_rawnetobj (LuaCore.lua_State luaState, int obj) public static int luanet_rawnetobj (LuaCore.lua_State luaState, int obj)
{ {
byte[] bytes = lua_touserdata (luaState, obj) as byte[]; return LuaCore.luanet_rawnetobj (luaState, obj);
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 (L, ud) != 0) {
bool isEqual;
/* does it have a metatable? */
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 (L, -(2) - 1);
if (isEqual) /* does it have the correct mt? */
return p;
}
}
return null;
} }
public static int luanet_checkudata (LuaCore.lua_State luaState, int ud, string tname) public static int luanet_checkudata (LuaCore.lua_State luaState, int ud, string tname)
{ {
object udata = checkudata_raw (luaState, ud, tname); return LuaCore.luanet_checkudata (luaState, ud, tname);
return !udata.IsNull () ? fourBytesToInt (udata as byte[]) : -1;
} }
public static bool luaL_checkmetatable (LuaCore.lua_State luaState, int index) public static void lua_error (LuaCore.lua_State luaState)
{ {
bool retVal = false; LuaCore.lua_error (luaState);
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 () public static bool lua_checkstack (LuaCore.lua_State luaState, int extra)
{ {
return tag; return LuaCore.lua_checkstack (luaState, extra) != 0;
} }
public static void luanet_newudata (LuaCore.lua_State luaState, int val) public static int lua_next (LuaCore.lua_State luaState, int index)
{ {
var userdata = lua_newuserdata (luaState, sizeof(int)) as byte[]; return LuaCore.lua_next (luaState, index);
intToFourBytes (val, userdata);
} }
public static int luanet_tonetobject (LuaCore.lua_State luaState, int index) public static void lua_pushlightuserdata (LuaCore.lua_State luaState, LuaCore.LuaTag udata)
{ {
byte[] udata; LuaCore.lua_pushlightuserdata (luaState, udata);
if (lua_type (luaState, index) == LuaTypes.UserData) {
if (luaL_checkmetatable (luaState, index)) {
udata = lua_touserdata (luaState, index) as byte[];
if (!udata.IsNull ())
return fourBytesToInt (udata);
}
udata = checkudata_raw (luaState, index, "luaNet_class") as byte[];
if (!udata.IsNull ())
return fourBytesToInt (udata);
udata = checkudata_raw (luaState, index, "luaNet_searchbase") as byte[];
if (!udata.IsNull ())
return fourBytesToInt (udata);
udata = checkudata_raw (luaState, index, "luaNet_function") as byte[];
if (!udata.IsNull ())
return fourBytesToInt (udata);
}
return -1;
} }
private static int fourBytesToInt (byte[] bytes) public static LuaCore.LuaTag luanet_gettag ()
{ {
return bytes [0] + (bytes [1] << 8) + (bytes [2] << 16) + (bytes [3] << 24); return LuaCore.luanet_gettag ();
} }
private static void intToFourBytes (int val, byte[] bytes)
{
// gfoot: is this really a good idea?
bytes [0] = (byte)val;
bytes [1] = (byte)(val >> 8);
bytes [2] = (byte)(val >> 16);
bytes [3] = (byte)(val >> 24);
}
} }
} }
\ No newline at end of file
...@@ -21,8 +21,10 @@ ...@@ -21,8 +21,10 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>
<MtouchLink>None</MtouchLink> <MtouchLink>Full</MtouchLink>
<MtouchDebug>True</MtouchDebug> <MtouchDebug>True</MtouchDebug>
<MtouchI18n />
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType> <DebugType>none</DebugType>
...@@ -31,7 +33,9 @@ ...@@ -31,7 +33,9 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<ConsolePause>False</ConsolePause> <ConsolePause>False</ConsolePause>
<MtouchLink>None</MtouchLink> <MtouchLink>Full</MtouchLink>
<MtouchI18n />
<MtouchArch>ARMv7</MtouchArch>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>True</DebugSymbols> <DebugSymbols>True</DebugSymbols>
......
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