Make "clone" a chaiscript based operation instead of forcing the user to register a clone method.
This commit is contained in:
@@ -422,20 +422,17 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a copy constructor for type T, also creates the standard
|
* Add a copy constructor for type T
|
||||||
* function "clone" for the type. "clone" is a synonym for
|
|
||||||
* the copy constructor.
|
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ModulePtr copy_constructor(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr copy_constructor(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||||
{
|
{
|
||||||
m->add(constructor<T (const T &)>(), type);
|
m->add(constructor<T (const T &)>(), type);
|
||||||
m->add(constructor<T (const T &)>(), "clone");
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add default and copy constructors (including "clone") for type T
|
* Add default and copy constructors for type T
|
||||||
*/
|
*/
|
||||||
template<typename T>
|
template<typename T>
|
||||||
ModulePtr basic_constructors(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
ModulePtr basic_constructors(const std::string &type, ModulePtr m = ModulePtr(new Module()))
|
||||||
|
@@ -121,6 +121,9 @@ namespace chaiscript
|
|||||||
m->add(user_type<Retro<Bidir_Range<ContainerType> > >(), type + "_Retro_Range");
|
m->add(user_type<Retro<Bidir_Range<ContainerType> > >(), type + "_Retro_Range");
|
||||||
m->add(user_type<typename ContainerType::iterator>(), type+"_Iterator");
|
m->add(user_type<typename ContainerType::iterator>(), type+"_Iterator");
|
||||||
|
|
||||||
|
copy_constructor<Bidir_Range<ContainerType> >(type + "_Range", m);
|
||||||
|
copy_constructor<Retro<Bidir_Range<ContainerType> > >(type + "_Retro_Range", m);
|
||||||
|
|
||||||
m->add(constructor<Bidir_Range<ContainerType> (ContainerType &)>(), "range");
|
m->add(constructor<Bidir_Range<ContainerType> (ContainerType &)>(), "range");
|
||||||
m->add(constructor<Bidir_Range<ContainerType> (typename ContainerType::iterator)>(), "range");
|
m->add(constructor<Bidir_Range<ContainerType> (typename ContainerType::iterator)>(), "range");
|
||||||
|
|
||||||
@@ -145,8 +148,6 @@ namespace chaiscript
|
|||||||
m->add(constructor<Retro<Bidir_Range<ContainerType> > (const Bidir_Range<ContainerType> &)>(), "retro");
|
m->add(constructor<Retro<Bidir_Range<ContainerType> > (const Bidir_Range<ContainerType> &)>(), "retro");
|
||||||
|
|
||||||
|
|
||||||
m->add(constructor<Bidir_Range<ContainerType> (const Bidir_Range<ContainerType> &)>(), "clone");
|
|
||||||
m->add(constructor<Retro<Bidir_Range<ContainerType> > (const Retro<Bidir_Range<ContainerType> > &)>(), "clone");
|
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -358,9 +359,7 @@ namespace chaiscript
|
|||||||
m->add(fun(&PairType::first), "first");
|
m->add(fun(&PairType::first), "first");
|
||||||
m->add(fun(&PairType::second), "second");
|
m->add(fun(&PairType::second), "second");
|
||||||
|
|
||||||
m->add(constructor<PairType ()>(), type);
|
basic_constructors<PairType>(type, m);
|
||||||
m->add(constructor<PairType (const PairType &)>(), type);
|
|
||||||
m->add(constructor<PairType (const PairType &)>(), "clone");
|
|
||||||
m->add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type);
|
m->add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type);
|
||||||
|
|
||||||
return m;
|
return m;
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#define chaiscript_prelude CODE_STRING(\
|
#define chaiscript_prelude CODE_STRING(\
|
||||||
def new(x) { eval(type_name(x))(); } \
|
def new(x) { eval(type_name(x))(); } \
|
||||||
|
def clone(x) { eval(type_name(x))(x); } \
|
||||||
# to_string for Pair()\n\
|
# to_string for Pair()\n\
|
||||||
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \
|
def to_string(x) : call_exists(first, x) && call_exists(second, x) { \
|
||||||
"<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \
|
"<" + x.first.to_string() + ", " + x.second.to_string() + ">"; \
|
||||||
|
Reference in New Issue
Block a user