本文整理汇总了C++中kaguya::State::setErrorHandler方法的典型用法代码示例。如果您正苦于以下问题:C++ State::setErrorHandler方法的具体用法?C++ State::setErrorHandler怎么用?C++ State::setErrorHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kaguya::State
的用法示例。
在下文中一共展示了State::setErrorHandler方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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);
}
示例2:
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
}
示例3:
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");
}
示例4: Register
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);
}
示例5:
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);
}
}
示例6: typeid
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
}