#include <tcl/pkg.h>
Public Member Functions | |
typedef void() | exit_callback () |
void | on_exit (exit_callback *callback) |
Specify a function to be called when the package is destroyed. | |
int | init_status () const throw () |
void | set_init_status_error () throw () |
Mark the package as having failed its initialization. | |
tcl::interpreter & | interp () throw () |
Returns the Tcl interpreter that was passed to the constructor. | |
void | handle_live_exception (const rutz::file_pos &pos) throw () |
Trap a live exception, and leave a message in the Tcl_Interp's result. | |
const char * | namesp_name () throw () |
Returns the package's "namespace name". | |
const char * | pkg_name () const throw () |
Return the package's "package name". | |
const char * | version () const throw () |
Returns the package version string. | |
void | namesp_alias (const char *namesp, const char *pattern="*") |
Export commands into a different namespace. | |
void | inherit_namesp (const char *namesp, const char *pattern="*") |
Import commands from a different namespace. | |
void | inherit_pkg (const char *name, const char *version=0) |
Import all commands and procedures defined in the named pkg. | |
void | eval (const char *script) |
Evaluates script using the package's Tcl_Interp . | |
void | link_var (const char *var_name, int &var) |
Links the var with the Tcl variable var_name. | |
void | link_var (const char *var_name, double &var) |
Links var with the Tcl variable var_name. | |
void | link_var_copy (const char *var_name, int var) |
Links a copy of var with the Tcl variable var_name. | |
void | link_var_copy (const char *var_name, double var) |
Links a copy of var with the Tcl variable var_name. | |
void | link_var_const (const char *var_name, int &var) |
Links var with the Tcl variable var_name. | |
void | link_var_const (const char *var_name, double &var) |
Links var with the Tcl variable var_name. | |
template<class Func> | |
void | def (const char *cmd_name, const char *usage, Func f, const rutz::file_pos &src_pos, int flags=0) |
template<class Func> | |
void | def_vec (const char *cmd_name, const char *usage, Func f, unsigned int keyarg, const rutz::file_pos &src_pos, int flags=0) |
template<class Func> | |
void | def_raw (const char *cmd_name, const arg_spec &spec, const char *usage, Func f, const rutz::file_pos &src_pos, int flags=0) |
template<class Func> | |
void | def_vec_raw (const char *cmd_name, const arg_spec &spec, const char *usage, Func f, unsigned int keyarg, const rutz::file_pos &src_pos, int flags=0) |
template<class C> | |
void | def_action (const char *cmd_name, void(C::*action_func)(), const rutz::file_pos &src_pos, int flags=0) |
template<class C> | |
void | def_action (const char *cmd_name, void(C::*action_func)() const, const rutz::file_pos &src_pos, int flags=0) |
template<class C, class T> | |
void | def_getter (const char *cmd_name, T(C::*getter_func)() const, const rutz::file_pos &src_pos, int flags=0) |
template<class C, class T> | |
void | def_setter (const char *cmd_name, void(C::*setter_func)(T), const rutz::file_pos &src_pos, int flags=0) |
template<class C, class T> | |
void | def_get_set (const char *cmd_name, T(C::*getter_func)() const, void(C::*setter_func)(T), const rutz::file_pos &src_pos, int flags=0) |
int | finish_init () throw () |
Called just prior to returning from the *_Init function. | |
Static Public Member Functions | |
static pkg * | create_in_macro (Tcl_Interp *interp, const char *name, const char *version) |
Don't call this directly! Use the PKG_CREATE macro instead. | |
static int | destroy_on_unload (Tcl_Interp *interp, const char *pkgname) |
Looks up the tcl::pkg associated with pkgname, and destroys it. | |
static pkg * | lookup (tcl::interpreter &interp, const char *name, const char *version=0) throw () |
Find a package given its name and version. | |
static void | verbose_init (bool verbose) throw () |
Control whether packages should be verbose as they start up. | |
Static Public Attributes | |
static const int | STATUS_OK = TCL_OK |
static const int | STATUS_ERR = TCL_ERROR |
Friends | |
struct | impl |
Classes | |
struct | impl |
tcl::pkg
is a class more managing groups of related tcl::command's
. It provides several facilities:
-- stores a list of tcl::command's
, and ensures that these are properly destroyed upon exit from Tcl
-- ensures that the package is provided to Tcl so that other packages can query for its presence
-- provides a set of functions to define Tcl commands from C++ functors
Definition at line 82 of file pkg.h.
void tcl::pkg::on_exit | ( | exit_callback * | callback | ) |
Specify a function to be called when the package is destroyed.
(Package destruction typically occurs at application exit, when the Tcl interpreter and all associated objects are destroyed.)
int tcl::pkg::destroy_on_unload | ( | Tcl_Interp * | interp, | |
const char * | pkgname | |||
) | [static] |
Looks up the tcl::pkg associated with pkgname, and destroys it.
This is intended to be called from pkg_Unload procedures called by Tcl when a dynamic library is unloaded. The return value can be returned as the return value of the pkg_Unload procedure; it will be TCL_OK (1) if the tcl::pkg was successfully found and destroyed and TCL_ERROR (0) otherwise.
tcl::pkg * tcl::pkg::lookup | ( | tcl::interpreter & | interp, | |
const char * | name, | |||
const char * | version = 0 | |||
) | throw () [static] |
Find a package given its name and version.
If the package is not already loaded, this function will attempt to "require" the package. If a null pointer is passed to version (the default), then any version will be acceptable. If no suitable package cannot be found or loaded, a null pointer will be returned.
Definition at line 286 of file pkg.cc.
References tcl::interpreter::get_result(), tcl::interpreter::intp(), tcl::interpreter::set_result(), and version().
Referenced by destroy_on_unload(), and inherit_pkg().
int tcl::pkg::init_status | ( | ) | const throw () |
const char * tcl::pkg::namesp_name | ( | ) | throw () |
Returns the package's "namespace name".
Note that the "namespace name" will be the same as the "package name" except possibly for capitalization. The "namespace name" is the name of the namespace that is used as the default prefix all commands contained in the package.
Definition at line 379 of file pkg.cc.
Referenced by inherit_pkg().
const char * tcl::pkg::pkg_name | ( | ) | const throw () |
Return the package's "package name".
Note that the "package name" will be the same as the "namespace name" except possibly for capitalization. The "package name" is the name that is passed to Tcl_PkgProvide() and Tcl_PkgProvide(), and has a well-defined capitalization scheme: first character uppercase, all remaining letters lowercase.
Definition at line 384 of file pkg.cc.
Referenced by finish_init().
void tcl::pkg::namesp_alias | ( | const char * | namesp, | |
const char * | pattern = "*" | |||
) |
Export commands into a different namespace.
Causes all of our package's currently defined commands and procedures to be imported into the specified other namespace. If pattern is different from the default value of "*", then only commands whose names match pattern according to glob rules will be aliased into the other namespace.
void tcl::pkg::inherit_namesp | ( | const char * | namesp, | |
const char * | pattern = "*" | |||
) |
Import commands from a different namespace.
Import all of the commands and procedures defined in the specified namespace into our own package namespace. If pattern is different from the default value of "*", then only commands whose names match pattern according to glob rules will be imported into our own package namespace.
Definition at line 345 of file pkg.cc.
References tcl::list::get(), and tcl::list::size().
Referenced by inherit_pkg().
void tcl::pkg::inherit_pkg | ( | const char * | name, | |
const char * | version = 0 | |||
) |
Import all commands and procedures defined in the named pkg.
If the named pkg has not yet been loaded, this function will attempt to load it via loookup(). If a null pointer is passed to version (the default), then any version will be acceptable.
Definition at line 366 of file pkg.cc.
References inherit_namesp(), lookup(), namesp_name(), rutz::sfmt(), and SRC_POS.
void tcl::pkg::link_var_copy | ( | const char * | var_name, | |
int | var | |||
) |
Links a copy of var with the Tcl variable var_name.
The Tcl variable will be read-only.
Definition at line 443 of file pkg.cc.
References rutz::shared_ptr< T >::get().
void tcl::pkg::link_var_copy | ( | const char * | var_name, | |
double | var | |||
) |
Links a copy of var with the Tcl variable var_name.
The Tcl variable will be read-only.
Definition at line 451 of file pkg.cc.
References rutz::shared_ptr< T >::get().
void tcl::pkg::link_var_const | ( | const char * | var_name, | |
int & | var | |||
) |
void tcl::pkg::link_var_const | ( | const char * | var_name, | |
double & | var | |||
) |
int tcl::pkg::finish_init | ( | ) | throw () |
Called just prior to returning from the *_Init function.
If the package's status is OK, then this does the relevant Tcl_PkgProvide and returns TCL_OK. Otherwise, it returns TCL_ERROR.
Definition at line 484 of file pkg.cc.
References pkg_name().