Remove boost from utility and associated module tests
This commit is contained in:
@@ -24,13 +24,11 @@ set(CPACK_PACKAGE_VENDOR "ChaiScript.com")
|
|||||||
set(CPACK_PACKAGE_CONTACT "contact@chaiscript.com")
|
set(CPACK_PACKAGE_CONTACT "contact@chaiscript.com")
|
||||||
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An embedded scripting language for C++")
|
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "An embedded scripting language for C++")
|
||||||
|
|
||||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libboost-dev (>=1.36.0)")
|
|
||||||
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
|
||||||
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
|
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
|
||||||
|
|
||||||
set(CPACK_RPM_PACKAGE_LICENSE "BSD")
|
set(CPACK_RPM_PACKAGE_LICENSE "BSD")
|
||||||
set(CPACK_RPM_PACKAGE_GROUP "Programming")
|
set(CPACK_RPM_PACKAGE_GROUP "Programming")
|
||||||
set(CPACK_RPM_PACKAGE_REQUIRES "boost-devel >= 1.36.0, boost-thread >= 1.36.0")
|
|
||||||
|
|
||||||
set(CHAI_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
|
set(CHAI_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
|
||||||
|
|
||||||
@@ -64,24 +62,13 @@ else()
|
|||||||
add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++0x)
|
add_definitions(-Wall -Wextra -Wshadow -pedantic -std=c++0x)
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
# -Wno-missing-field-initializers is for boost on macos
|
add_definitions(-Wno-sign-compare)
|
||||||
add_definitions(-Wno-missing-field-initializers -Wno-sign-compare)
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(include)
|
include_directories(include)
|
||||||
|
|
||||||
set(Boost_ADDITIONAL_VERSIONS "1.44" "1.44.0" "1.43" "1.43.0" "1.42" "1.42.0" "1.41")
|
|
||||||
set(Boost_USE_MULTITHREADED ON)
|
|
||||||
|
|
||||||
if (MULTITHREAD_SUPPORT_ENABLED)
|
if (MULTITHREAD_SUPPORT_ENABLED)
|
||||||
find_package(Boost 1.36.0 COMPONENTS thread)
|
|
||||||
|
|
||||||
if (Boost_FOUND)
|
|
||||||
link_directories( ${Boost_LIBRARY_DIRS} )
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "Can not find Boost")
|
|
||||||
endif(Boost_FOUND)
|
|
||||||
else()
|
else()
|
||||||
add_definitions(-DCHAISCRIPT_NO_THREADS)
|
add_definitions(-DCHAISCRIPT_NO_THREADS)
|
||||||
endif()
|
endif()
|
||||||
@@ -90,20 +77,13 @@ if (CMAKE_HOST_UNIX)
|
|||||||
set(DYNAMIC_LOADER "dl")
|
set(DYNAMIC_LOADER "dl")
|
||||||
endif(CMAKE_HOST_UNIX)
|
endif(CMAKE_HOST_UNIX)
|
||||||
|
|
||||||
if (MSVC)
|
|
||||||
# Boost on MSVC does automatic linking
|
|
||||||
set(LIBS ${DYNAMIC_LOADER} ${READLINE_LIB})
|
set(LIBS ${DYNAMIC_LOADER} ${READLINE_LIB})
|
||||||
else()
|
|
||||||
set(LIBS ${DYNAMIC_LOADER} ${Boost_LIBRARIES} ${READLINE_LIB})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if (CMAKE_COMPILER_2005)
|
if (CMAKE_COMPILER_2005)
|
||||||
# vs2005 is a bit too loud about possible loss of data warnings
|
# vs2005 is a bit too loud about possible loss of data warnings
|
||||||
# ADD_DEFINITIONS(/wd4244)
|
# ADD_DEFINITIONS(/wd4244)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
|
||||||
include_directories(${Boost_INCLUDE_DIR})
|
|
||||||
add_executable(chai src/main.cpp)
|
add_executable(chai src/main.cpp)
|
||||||
target_link_libraries(chai ${LIBS})
|
target_link_libraries(chai ${LIBS})
|
||||||
|
|
||||||
|
@@ -8,89 +8,32 @@
|
|||||||
#define CHAISCRIPT_UTILITY_UTILITY_HPP_
|
#define CHAISCRIPT_UTILITY_UTILITY_HPP_
|
||||||
|
|
||||||
#include "../chaiscript.hpp"
|
#include "../chaiscript.hpp"
|
||||||
#include <boost/preprocessor.hpp>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#define CHAISCRIPT_MODULE(_info) BOOST_PP_SEQ_ELEM(0, _info)
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_ELEM(_info) BOOST_PP_SEQ_ELEM(1, _info)
|
|
||||||
|
|
||||||
#define CHAISCRIPT_METHOD(_info, _method) & CHAISCRIPT_CLASS_ELEM(_info) :: BOOST_PP_SEQ_ELEM(0, _method)
|
|
||||||
|
|
||||||
#define CHAISCRIPT_METHOD_NAME(_info, _method) \
|
|
||||||
BOOST_PP_SEQ_ELEM(3, _info) (BOOST_PP_STRINGIZE(BOOST_PP_SEQ_ELEM(0, _method ) ) )
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_NAME(_info) \
|
|
||||||
BOOST_PP_SEQ_ELEM(2, _info) (BOOST_PP_STRINGIZE(CHAISCRIPT_CLASS_ELEM(_info) ) )
|
|
||||||
|
|
||||||
#define CHAISCRIPT_METHOD_SIGNATURE_PART(_r, _info, _i, _method_part) \
|
|
||||||
BOOST_PP_EXPR_IF(BOOST_PP_EQUAL(_i, 1), < _method_part > )
|
|
||||||
|
|
||||||
#define CHAISCRIPT_METHOD_SIGNATURE(_info, _method) \
|
|
||||||
BOOST_PP_SEQ_FOR_EACH_I(CHAISCRIPT_METHOD_SIGNATURE_PART, _info, _method)
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_CONSTRUCTOR(_r, _info, _constructor) \
|
|
||||||
CHAISCRIPT_MODULE(_info) ->add BOOST_PP_LPAREN() chaiscript::constructor<_constructor>() BOOST_PP_COMMA() CHAISCRIPT_CLASS_NAME(_info) BOOST_PP_RPAREN() ;
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_METHOD(_r, _info, _method) \
|
|
||||||
CHAISCRIPT_MODULE(_info) ->add BOOST_PP_LPAREN() chaiscript::fun CHAISCRIPT_METHOD_SIGNATURE(_info, _method) \
|
|
||||||
BOOST_PP_LPAREN() CHAISCRIPT_METHOD(_info, _method) BOOST_PP_RPAREN() BOOST_PP_COMMA() CHAISCRIPT_METHOD_NAME(_info, _method)BOOST_PP_RPAREN() ;
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_CONSTRUCTORS(_info, _constructors) \
|
|
||||||
BOOST_PP_SEQ_FOR_EACH(CHAISCRIPT_CLASS_CONSTRUCTOR, _info, _constructors)
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_METHODS(_info, _methods) \
|
|
||||||
BOOST_PP_SEQ_FOR_EACH(CHAISCRIPT_CLASS_METHOD, _info, _methods)
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_EX(_module, _class_name, _class_name_translator, _method_name_translator, _constructors, _methods) \
|
|
||||||
{ \
|
|
||||||
_module->add(chaiscript::user_type<_class_name>(), _class_name_translator (BOOST_PP_STRINGIZE(_class_name))); \
|
|
||||||
CHAISCRIPT_CLASS_CONSTRUCTORS((_module)(_class_name)(_class_name_translator), _constructors) \
|
|
||||||
CHAISCRIPT_CLASS_METHODS((_module)(_class_name)(_class_name_translator)(_method_name_translator), _methods) \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_NO_CONSTRUCTOR_EX(_module, _class_name, _class_name_translator, _method_name_translator, _methods) \
|
|
||||||
{ \
|
|
||||||
_module->add(chaiscript::user_type<_class_name>(), _class_name_translator (BOOST_PP_STRINGIZE(_class_name))); \
|
|
||||||
CHAISCRIPT_CLASS_METHODS((_module)(_class_name)(_class_name_translator)(_method_name_translator), _methods) \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS(_module, _class_name, _constructors, _methods) \
|
|
||||||
CHAISCRIPT_CLASS_EX(_module, _class_name, chaiscript::utility::class_name_translator, \
|
|
||||||
chaiscript::utility::method_name_translator, _constructors, _methods)
|
|
||||||
|
|
||||||
#define CHAISCRIPT_CLASS_NO_CONSTRUCTOR(_module, _class_name, _methods) \
|
|
||||||
CHAISCRIPT_CLASS_NO_CONSTRUCTOR_EX(_module, _class_name, chaiscript::utility::class_name_translator, \
|
|
||||||
chaiscript::utility::method_name_translator, _methods)
|
|
||||||
|
|
||||||
namespace chaiscript
|
namespace chaiscript
|
||||||
{
|
{
|
||||||
/// \brief Classes and functions which provide general utility to the end user.
|
|
||||||
namespace utility
|
namespace utility
|
||||||
{
|
{
|
||||||
inline std::string class_name_translator(const std::string &t_name)
|
|
||||||
|
template<typename Class, typename ModuleType>
|
||||||
|
void add_class(ModuleType &t_module,
|
||||||
|
const std::string &t_classname,
|
||||||
|
const std::vector<chaiscript::Proxy_Function> &t_constructors,
|
||||||
|
const std::vector<std::pair<chaiscript::Proxy_Function, std::string>> &t_funcs)
|
||||||
{
|
{
|
||||||
size_t colon = t_name.rfind("::");
|
t_module.add(chaiscript::user_type<Class>(), t_classname);
|
||||||
if (colon != std::string::npos)
|
|
||||||
|
for(const chaiscript::Proxy_Function &ctor: t_constructors)
|
||||||
{
|
{
|
||||||
return t_name.substr(colon+2, std::string::npos);
|
t_module.add(ctor, t_classname);
|
||||||
} else {
|
|
||||||
return t_name;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string method_name_translator(const std::string &t_name)
|
for(auto fun: t_funcs)
|
||||||
{
|
{
|
||||||
size_t namestart = t_name.rfind("operator");
|
t_module.add(fun.first, fun.second);
|
||||||
namestart = (namestart == std::string::npos)?0:namestart+strlen("operator");
|
|
||||||
|
|
||||||
if (namestart == 0)
|
|
||||||
{
|
|
||||||
namestart = t_name.rfind("::");
|
|
||||||
namestart = (namestart == std::string::npos)?0:namestart+strlen("::");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return t_name.substr(namestart, std::string::npos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -52,40 +52,46 @@ CHAISCRIPT_MODULE_EXPORT chaiscript::ModulePtr create_chaiscript_module_reflect
|
|||||||
|
|
||||||
chaiscript::bootstrap::standard_library::vector_type<std::vector<std::shared_ptr<chaiscript::AST_Node> > >("AST_NodeVector", m);
|
chaiscript::bootstrap::standard_library::vector_type<std::vector<std::shared_ptr<chaiscript::AST_Node> > >("AST_NodeVector", m);
|
||||||
|
|
||||||
CHAISCRIPT_CLASS_NO_CONSTRUCTOR( m,
|
using namespace chaiscript;
|
||||||
chaiscript::exception::eval_error,
|
|
||||||
((reason))
|
chaiscript::utility::add_class<chaiscript::exception::eval_error>(*m,
|
||||||
((call_stack))
|
"eval_error",
|
||||||
|
{ },
|
||||||
|
{ {fun(&chaiscript::exception::eval_error::reason), "reason"},
|
||||||
|
{fun(&chaiscript::exception::eval_error::call_stack), "call_stack"} }
|
||||||
);
|
);
|
||||||
|
|
||||||
CHAISCRIPT_CLASS( m,
|
chaiscript::utility::add_class<chaiscript::File_Position>(*m,
|
||||||
chaiscript::File_Position,
|
"File_Position",
|
||||||
(chaiscript::File_Position())
|
{ constructor<File_Position()>(),
|
||||||
(chaiscript::File_Position(int,int)),
|
constructor<File_Position(int, int)>() },
|
||||||
((line))
|
{ {fun(&File_Position::line), "line"},
|
||||||
((column))
|
{fun(&File_Position::column), "column"} }
|
||||||
);
|
);
|
||||||
|
|
||||||
CHAISCRIPT_CLASS_NO_CONSTRUCTOR( m,
|
chaiscript::utility::add_class<AST_Node>(*m,
|
||||||
chaiscript::AST_Node,
|
"AST_Node",
|
||||||
((text))
|
{ },
|
||||||
((identifier))
|
{ {fun(&AST_Node::text), "text"},
|
||||||
((filename))
|
{fun(&AST_Node::identifier), "identifier"},
|
||||||
((start))
|
{fun(&AST_Node::filename), "filename"},
|
||||||
((end))
|
{fun(&AST_Node::start), "start"},
|
||||||
((internal_to_string))
|
{fun(&AST_Node::end), "end"},
|
||||||
((children))
|
{fun(&AST_Node::internal_to_string), "internal_to_string"},
|
||||||
((replace_child))
|
{fun(&AST_Node::children), "children"},
|
||||||
|
{fun(&AST_Node::replace_child), "replace_child"}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
CHAISCRIPT_CLASS( m,
|
chaiscript::utility::add_class<parser::ChaiScript_Parser>(*m,
|
||||||
chaiscript::parser::ChaiScript_Parser,
|
"ChaiScript_Parser",
|
||||||
(chaiscript::parser::ChaiScript_Parser ()),
|
{ constructor<parser::ChaiScript_Parser ()>() },
|
||||||
((parse))
|
{ {fun(&parser::ChaiScript_Parser::parse), "parse"},
|
||||||
((ast))
|
{fun(&parser::ChaiScript_Parser::ast), "ast"} }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -29,11 +29,11 @@ int main()
|
|||||||
{
|
{
|
||||||
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
||||||
|
|
||||||
CHAISCRIPT_CLASS( m,
|
chaiscript::utility::add_class<Test>(*m,
|
||||||
Test,
|
"Test",
|
||||||
(Test ())
|
{ chaiscript::constructor<Test ()>(),
|
||||||
(Test (const Test &)),
|
chaiscript::constructor<Test (const Test &)>() },
|
||||||
((count))
|
{ {chaiscript::fun(&Test::count), "count"} }
|
||||||
);
|
);
|
||||||
|
|
||||||
chaiscript::ChaiScript chai;
|
chaiscript::ChaiScript chai;
|
||||||
|
@@ -15,18 +15,24 @@ int main()
|
|||||||
|
|
||||||
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
chaiscript::ModulePtr m = chaiscript::ModulePtr(new chaiscript::Module());
|
||||||
|
|
||||||
CHAISCRIPT_CLASS( m,
|
using namespace chaiscript;
|
||||||
Test,
|
|
||||||
(Test ())
|
chaiscript::utility::add_class<Test>(*m,
|
||||||
(Test (const Test &)),
|
"Test",
|
||||||
((function))
|
{ constructor<Test ()>(),
|
||||||
((function2))
|
constructor<Test (const Test &)>() },
|
||||||
((function3))
|
{ {fun(&Test::function), "function"},
|
||||||
((functionOverload)(std::string (Test::*)(double)))
|
{fun(&Test::function2), "function2"},
|
||||||
((functionOverload)(std::string (Test::*)(int)))
|
{fun(&Test::function3), "function3"},
|
||||||
((operator=))
|
{fun<std::string (Test::*)(double)>(&Test::functionOverload), "functionOverload"},
|
||||||
|
{fun<std::string (Test::*)(int)>(&Test::functionOverload), "functionOverload"},
|
||||||
|
{fun<Test & (Test::*)(const Test &)>(&Test::operator=), "="}
|
||||||
|
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
chaiscript::ChaiScript chai;
|
chaiscript::ChaiScript chai;
|
||||||
chai.add(m);
|
chai.add(m);
|
||||||
if (chai.eval<std::string>("var t = Test(); t.function2(); ") == "Function2"
|
if (chai.eval<std::string>("var t = Test(); t.function2(); ") == "Function2"
|
||||||
|
Reference in New Issue
Block a user