Further small refactorings, tweaks.

This commit is contained in:
jrp2014 2018-03-24 18:19:07 +00:00
parent 55717cb115
commit a8aa4ce273
7 changed files with 18 additions and 17 deletions

View File

@ -1286,7 +1286,7 @@ namespace chaiscript
return m_stack_holder->stacks.back(); return m_stack_holder->stacks.back();
} }
parser::ChaiScript_Parser_Base &get_parser() parser::ChaiScript_Parser_Base &get_parser() const
{ {
return m_parser.get(); return m_parser.get();
} }

View File

@ -629,7 +629,7 @@ namespace chaiscript
fpp.save_params(params); fpp.save_params(params);
try { try {
retval = t_ss->call_member(m_fun_name, m_loc, std::move(params), has_function_params, t_ss.conversions()); retval = t_ss->call_member(m_fun_name, m_loc, params, has_function_params, t_ss.conversions());
} }
catch(const exception::dispatch_error &e){ catch(const exception::dispatch_error &e){
if (e.functions.empty()) if (e.functions.empty())
@ -1097,7 +1097,7 @@ namespace chaiscript
vec.push_back(detail::clone_if_necessary(child->eval(t_ss), m_loc, t_ss)); vec.push_back(detail::clone_if_necessary(child->eval(t_ss), m_loc, t_ss));
} }
} }
return const_var(std::move(vec)); return const_var(vec);
} }
catch (const exception::dispatch_error &) { catch (const exception::dispatch_error &) {
throw exception::eval_error("Can not find appropriate 'clone' or copy constructor for vector elements"); throw exception::eval_error("Can not find appropriate 'clone' or copy constructor for vector elements");
@ -1123,7 +1123,7 @@ namespace chaiscript
detail::clone_if_necessary(child->children[1]->eval(t_ss), m_loc, t_ss))); detail::clone_if_necessary(child->children[1]->eval(t_ss), m_loc, t_ss)));
} }
return const_var(std::move(retval)); return const_var(retval);
} }
catch (const exception::dispatch_error &e) { catch (const exception::dispatch_error &e) {
throw exception::eval_error("Can not find appropriate copy constructor or 'clone' while inserting into Map.", e.parameters, e.functions, false, *t_ss); throw exception::eval_error("Can not find appropriate copy constructor or 'clone' while inserting into Map.", e.parameters, e.functions, false, *t_ss);

View File

@ -113,7 +113,7 @@ int main(int /*argc*/, char * /*argv*/[]) {
//Call bound version of do_callbacks //Call bound version of do_callbacks
chai("do_callbacks()"); chai("do_callbacks()");
std::function<void ()> caller = chai.eval<std::function<void ()> >( const std::function<void ()> caller = chai.eval<std::function<void ()> >(
R"(fun() { system.do_callbacks("From Functor"); })" R"(fun() { system.do_callbacks("From Functor"); })"
); );
caller(); caller();
@ -165,8 +165,8 @@ int main(int /*argc*/, char * /*argv*/[]) {
chai.add(fun(&bound_log, std::string("Msg")), "BoundFun"); chai.add(fun(&bound_log, std::string("Msg")), "BoundFun");
//Dynamic objects test //Dynamic objects test
chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Function("TestType", fun(&hello_world))), "hello_world"); chai.add(std::static_pointer_cast<dispatch::Proxy_Function_Base>(std::make_shared<dispatch::detail::Dynamic_Object_Function>("TestType", fun(&hello_world))), "hello_world");
chai.add(chaiscript::Proxy_Function(new dispatch::detail::Dynamic_Object_Constructor("TestType", fun(&hello_constructor))), "TestType"); chai.add(std::static_pointer_cast<dispatch::Proxy_Function_Base>(std::make_shared<dispatch::detail::Dynamic_Object_Constructor>("TestType", fun(&hello_constructor))), "TestType");
// chai.add(fun(std::function<Boxed_Value (dispatch::Dynamic_Object &)>(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", std::placeholders::_1))), "attr"); // chai.add(fun(std::function<Boxed_Value (dispatch::Dynamic_Object &)>(std::bind(&dispatch::detail::Dynamic_Object_Attribute::func, "TestType", "attr", std::placeholders::_1))), "attr");
chai.eval("var x = TestType()"); chai.eval("var x = TestType()");

View File

@ -75,7 +75,7 @@ int main()
Factory f{}; Factory f{};
chai.add(chaiscript::var(&f), "f"); chai.add(chaiscript::var(&f), "f");
std::string script = R""( const std::string script = R""(
f.make_entity(10,10,1,1,"entity1").updater = fun(e){ e.x += 1; e.y += 1 }; f.make_entity(10,10,1,1,"entity1").updater = fun(e){ e.x += 1; e.y += 1 };
f.make_entity(10,10,10,10,"entity2").updater = fun(e){ e.x += 2; e.y += 2 }; f.make_entity(10,10,10,10,"entity2").updater = fun(e){ e.x += 2; e.y += 2 };
f.make_entity(10,10,20,20,"entity3"); f.make_entity(10,10,20,20,"entity3");

View File

@ -272,6 +272,7 @@ int main(int argc, char *argv[])
#pragma warning(disable : 4996) #pragma warning(disable : 4996)
#endif #endif
// TODO:: Use _dupenv_s instead
const char *usepath = getenv("CHAI_USE_PATH"); const char *usepath = getenv("CHAI_USE_PATH");
const char *modulepath = getenv("CHAI_MODULE_PATH"); const char *modulepath = getenv("CHAI_MODULE_PATH");
@ -375,7 +376,7 @@ int main(int argc, char *argv[])
mode = eFile; mode = eFile;
} }
chaiscript::Boxed_Value val; /* never accessed? */ chaiscript::Boxed_Value val;
try { try {
switch (mode) { switch (mode) {
case eInteractive: interactive(chai); break; case eInteractive: interactive(chai); break;

View File

@ -76,7 +76,7 @@ int main()
chai.add(chaiscript::user_type<BaseClass>(), "BaseClass"); chai.add(chaiscript::user_type<BaseClass>(), "BaseClass");
chai.add(chaiscript::user_type<ChaiScriptDerived>(), "ChaiScriptDerived"); chai.add(chaiscript::user_type<ChaiScriptDerived>(), "ChaiScriptDerived");
std::string script = R""( const std::string script = R""(
def MakeDerived() { def MakeDerived() {
return ChaiScriptDerived( return ChaiScriptDerived(
// create a dynamically created array and pass it in to the constructor // create a dynamically created array and pass it in to the constructor

View File

@ -4931,17 +4931,17 @@ inline void AssertionHandler::handleExceptionNotThrownAsExpected() {
m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
} }
void AssertionHandler::handleUnexpectedExceptionNotThrown() { inline void AssertionHandler::handleUnexpectedExceptionNotThrown() {
m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction ); m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction );
} }
void AssertionHandler::handleThrowingCallSkipped() { inline void AssertionHandler::handleThrowingCallSkipped() {
m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction); m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
} }
// This is the overload that takes a string and infers the Equals matcher from it // This is the overload that takes a string and infers the Equals matcher from it
// The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { inline void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) {
handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString );
} }
@ -4950,11 +4950,11 @@ inline void AssertionHandler::handleExceptionNotThrownAsExpected() {
// start catch_assertionresult.cpp // start catch_assertionresult.cpp
namespace Catch { namespace Catch {
AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): inline AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
lazyExpression(_lazyExpression), lazyExpression(_lazyExpression),
resultType(_resultType) {} resultType(_resultType) {}
std::string AssertionResultData::reconstructExpression() const { inline std::string AssertionResultData::reconstructExpression() const {
if( reconstructedExpression.empty() ) { if( reconstructedExpression.empty() ) {
if( lazyExpression ) { if( lazyExpression ) {
@ -4966,13 +4966,13 @@ namespace Catch {
return reconstructedExpression; return reconstructedExpression;
} }
AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) inline AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
: m_info( info ), : m_info( info ),
m_resultData( data ) m_resultData( data )
{} {}
// Result was a success // Result was a success
bool AssertionResult::succeeded() const { inline bool AssertionResult::succeeded() const {
return Catch::isOk( m_resultData.resultType ); return Catch::isOk( m_resultData.resultType );
} }