Commit e25a411a authored by Vinicius Jarina's avatar Vinicius Jarina
Browse files

Fix #337 Array access on an object that doesn't implement array access does not throw an error

parent 805a5e33
......@@ -355,8 +355,11 @@ namespace NLua
if (fallback != 0)
return fallback;
if (!string.IsNullOrEmpty(methodName))
if (!string.IsNullOrEmpty(methodName) || index != null)
{
if (string.IsNullOrEmpty(methodName))
methodName = index.ToString();
return PushInvalidMethodCall(luaState, objType, methodName);
}
......@@ -1197,7 +1200,7 @@ namespace NLua
{
var luaState = LuaState.FromIntPtr(state);
var translator = ObjectTranslatorPool.Instance.Find(luaState);
translator.ThrowError(luaState, "Trying to invoke invalid method");
translator.ThrowError(luaState, "Trying to invoke invalid method or an access an invalid index");
luaState.PushNil();
return 1;
}
......
......@@ -2700,6 +2700,17 @@ namespace NLuaTest
Assert.AreEqual(Enumeration.First, result, "#1");
}
[Test]
public void InvalidArrayIndex()
{
var lua = new Lua();
lua["main"] = new Person();
object result = lua.DoString("return main[15]")[0];
Assert.AreNotEqual(15, result, "#1");
}
static Lua m_lua;
}
......
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