Skip to content

Commit

Permalink
Added NewLib test
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusjarina committed Nov 8, 2020
1 parent 5ed9a4f commit 27f02d2
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/Tests/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,56 @@ public void TestWarning()
}
}

private static LuaRegister[] fooReg = {
new LuaRegister {
name = "foo",
function = Foo,
},
new LuaRegister {
name = null,
function = null,
}
};

[Test]
public static void TestNewLib()
{
var lua = new Lua();

lua.RequireF("foobar", OpenFoo, true);

lua.DoString("s = foobar.foo()");

lua.GetGlobal("s");

bool check = lua.IsString(-1);
string s = lua.ToString(-1, false);

Assert.IsTrue(check, "#1");
Assert.AreEqual("bar", s, "#2");

lua.Dispose();
}

#if MONOTOUCH
[MonoPInvokeCallback(typeof(LuaFunction))]
#endif
static int OpenFoo(IntPtr state)
{
var lua = Lua.FromIntPtr(state);
lua.NewLib(fooReg);
return 1;
}

#if MONOTOUCH
[MonoPInvokeCallback(typeof(LuaFunction))]
#endif
static int Foo(IntPtr state)
{
var lua = Lua.FromIntPtr(state);

lua.PushString("bar");
return 1;
}
}
}

0 comments on commit 27f02d2

Please sign in to comment.