Exemplo n.º 1
0
KAGUYA_TEST_FUNCTION_DEF(load_string)(kaguya::State& state)
{
	kaguya::LuaRef luafun = state.loadstring("assert(11 == 11);return true");
	TEST_CHECK(luafun() != false);
	state.setErrorHandler(ignore_error_fun);
	kaguya::LuaRef errorref = state.loadstring("function() e");//syntax error
	TEST_CHECK(!errorref);
}
Exemplo n.º 2
0
KAGUYA_TEST_FUNCTION_DEF(set_error_function)(kaguya::State& state)
{
	error_count = 0;
	state.setErrorHandler(error_fun);
	TEST_CHECK(!state("awdorgkwl;gw"));

	TEST_CHECK(error_count == 1);
	state["yy"]["yy"]["yy"]();
	TEST_CHECK(error_count > 0);
}
Exemplo n.º 3
0
KAGUYA_TEST_FUNCTION_DEF(nil_to_nullpointer)(kaguya::State& state)
{
	state["pointerfun"] = kaguya::function(pointerfun);
	TEST_CHECK(state("pointerfun(nil)"));
	state["const_pointerfun"] = kaguya::function(const_pointerfun);
	TEST_CHECK(state("const_pointerfun(nil)"));

	state.setErrorHandler(ignore_error_fun);
	TEST_CHECK(!state("pointerfun(32)"));// is error
	TEST_CHECK(!state("pointerfun('232')"));// is error
}
Exemplo n.º 4
0
KAGUYA_TEST_FUNCTION_DEF(defaultarguments)(kaguya::State& state)
{
	state.setErrorHandler(error_fun);
	state["defargfn"] = kaguya::function(defargfn_wrapper());
	state["defargfn2"] = kaguya::function(defargfn_wrapper2());

	state.dostring("defargfn('abc')");
	last_error_message.find("[OPT]int,[OPT]int,[OPT]int");


	state.dostring("defargfn2('abc')");
	last_error_message.find("int,int,[OPT]int");
}
Exemplo n.º 5
0
void LuaInterfaceBase::Register(kaguya::State& state)
{
    state["RTTRBase"].setClass(kaguya::ClassMetatable<LuaInterfaceBase>()
        .addMemberFunction("Log", &LuaInterfaceBase::Log)
        .addMemberFunction("IsHost", &LuaInterfaceBase::IsHost)
        .addMemberFunction("GetLocalPlayerIdx", &LuaInterfaceBase::GetLocalPlayerIdx)
        .addMemberFunction("MsgBox", &LuaInterfaceBase::MsgBox)
        .addMemberFunction("MsgBox", &LuaInterfaceBase::MsgBox2)
        .addMemberFunction("MsgBoxEx", &LuaInterfaceBase::MsgBoxEx)
        .addMemberFunction("MsgBoxEx", &LuaInterfaceBase::MsgBoxEx2)
        );
    state.setErrorHandler(ErrorHandler);
}
Exemplo n.º 6
0
KAGUYA_TEST_FUNCTION_DEF(defaultarguments)(kaguya::State& state)
{
	state.setErrorHandler(error_fun);
	state["defargfn"] = kaguya::function(defargfn_wrapper());
	state["defargfn2"] = kaguya::function(defargfn_wrapper2());

	std::string intname = kaguya::util::pretty_name(typeid(int));

	if (intname == "int")
	{
		state.dostring("defargfn('abc')");
		TEST_CHECK_M(last_error_message.find("[OPT]int,[OPT]int,[OPT]int") != std::string::npos, last_error_message);
		state.dostring("defargfn2('abc',3)");
		TEST_CHECK_M(last_error_message.find("int,int,[OPT]int") != std::string::npos, last_error_message);
	}
}
Exemplo n.º 7
0
KAGUYA_TEST_FUNCTION_DEF(function_call_error)(kaguya::State& state)
{
	error_count = 0;
	state.setErrorHandler(error_fun);

	state["errofun"] = kaguya::function(error_fun);
	state["errofun"](33);

	TEST_CHECK(error_count == 1);

	kaguya::LuaRef f;
	f.resume<void>();
	f.call<void>();
	TEST_COMPARE_EQ(f.threadStatus(), LUA_ERRRUN);
	TEST_COMPARE_EQ(state.newRef(1).threadStatus(), LUA_ERRRUN);
}
Exemplo n.º 8
0
KAGUYA_TEST_FUNCTION_DEF(errorThrowing)(kaguya::State& state)
{
	state["foobar"] = kaguya::overload(foobar1, foobar2, foobar3);
	state["Foo"].setClass(kaguya::ClassMetatable<Foo>().addConstructor());
	state.setErrorHandler(registerError);
	TEST_CHECK(!state("foobar()"));
	TEST_EQUAL(errorOccurred, true);
	TEST_CHECK(lastMsg.find("candidate is:") != std::string::npos);
	lastMsg = lastMsg.substr(lastMsg.find("candidate is:\n"));
	lastMsg = lastMsg.substr(0, lastMsg.find("stack "));
	std::vector<std::string> parts = remove_empty(split(lastMsg, '\n'));
	TEST_EQUAL(parts.size(), 4);
	std::string intName = typeid(int).name();
	TEST_CHECK(parts[1].find(intName) != std::string::npos);
	TEST_CHECK(parts[2].find(intName + "," + intName) != std::string::npos);
	TEST_CHECK(parts[3].find(intName + "," + typeid(Foo).name() + "," + intName) != std::string::npos);

	errorOccurred = false;
	TEST_CHECK(!state("foobar(Foo.new(), 1, 1)"));
	TEST_EQUAL(errorOccurred, true);
	TEST_CHECK(lastMsg.find("candidate is:") != std::string::npos);

	errorOccurred = false;
	TEST_CHECK(!state("foobar(1)"));
	TEST_EQUAL(errorOccurred, true);
	TEST_CHECK(lastMsg.find("MyRuntimeError") != std::string::npos);

#ifndef KAGUYA_NO_STD_MAP_TO_TABLE
	errorOccurred = false;
	state["noTable"] = 5;
	std::map<int, int> map = state["noTable"];
	TEST_EQUAL(errorOccurred, true);
	TEST_CHECK(lastMsg.find("type mismatch") != std::string::npos);

	errorOccurred = false;
	state["noTable"] = 5;
	std::vector<int> vec = state["noTable"];
	TEST_EQUAL(errorOccurred, true);
	TEST_CHECK(lastMsg.find("type mismatch") != std::string::npos);
#endif
}