OpenCog Framework  Branch: master, revision 6f0b7fc776b08468cf1b74aa9db028f387b4f0c0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SchemeModule.cc
Go to the documentation of this file.
1 /*
2  * SchemeModule.cc
3  *
4  * Simplified API for creating guile modules.
5  * Copyright (c) 2008, 2014, 2015 Linas Vepstas <linas@linas.org>
6  */
7 
12 
13 using namespace opencog;
14 
16  const char* funcname, const char* modname)
17  : _func(f), _pred(NULL), _name(funcname)
18 {
19  define_scheme_primitive(_name, &FunctionWrap::wrapper, this, modname);
20 }
21 
23  const char* funcname, const char* modname)
24  : _func_htq(f), _pred(NULL), _name(funcname)
25 {
26  define_scheme_primitive(_name, &FunctionWrap::wrapper_htq, this, modname);
27 }
28 
30  const char* funcname, const char* modname)
31  : _func(NULL), _pred(p), _name(funcname)
32 {
33  define_scheme_primitive(_name, &FunctionWrap::prapper, this, modname);
34 }
35 
37 {
38  // XXX we should also allow opt-args to be a list of handles
40  return _func(as, h);
41 }
42 
44 {
46  return _func_htq(as, h, t, seq);
47 }
48 
50 {
51  // XXX we should also allow opt-args to be a list of handles
53  return _pred(as, h);
54 }
55 
56 // ========================================================
57 
58 ModuleWrap::ModuleWrap(const char* m) :
59  _modname(m)
60 {}
61 
63 {
64  scm_with_guile(init_in_guile, this);
65 }
66 
68 {
69  // init_in_module(NULL);
70  ModuleWrap* self = (ModuleWrap*) data;
71 
72  scm_c_define_module(self->_modname, init_in_module, data);
73  scm_c_use_module(self->_modname);
74 
75  return NULL;
76 }
77 
81 {
82  ModuleWrap* self = (ModuleWrap*) data;
83  self->init();
84 }
85 
87 {
88 }
Handle wrapper_htq(Handle, Type, const HandleSeq &)
Definition: SchemeModule.cc:43
static void * init_in_guile(void *)
Definition: SchemeModule.cc:67
static void init_in_module(void *)
Definition: SchemeModule.cc:80
Handle(* _func_htq)(AtomSpace *, const Handle &, Type, const HandleSeq &)
Definition: SchemeModule.h:24
std::vector< Handle > HandleSeq
a list of handles
Definition: Handle.h:246
void module_init(void)
Definition: SchemeModule.cc:62
std::shared_ptr< TruthValue > TruthValuePtr
Definition: TruthValue.h:85
Handle(* _func)(AtomSpace *, const Handle &)
Definition: SchemeModule.h:23
TruthValuePtr prapper(Handle)
Definition: SchemeModule.cc:49
FunctionWrap(Handle(*)(AtomSpace *, const Handle &), const char *, const char *)
Handle wrapper(Handle)
Definition: SchemeModule.cc:36
virtual void init(void)=0
TruthValuePtr(* _pred)(AtomSpace *, const Handle &)
Definition: SchemeModule.h:29
ModuleWrap(const char *)
Definition: SchemeModule.cc:58
unsigned short Type
type of Atoms, represented as short integer (16 bits)
Definition: types.h:40
const char * _name
Definition: SchemeModule.h:32
static AtomSpace * ss_get_env_as(const char *)