int scm_c_symbol_exists(const char *name) { SCM sym; SCM var; sym = scm_str2symbol(name); /* Check to see if the symbol exists */ var = scm_sym2var (sym, scm_current_module_lookup_closure(), SCM_BOOL_F ); if (var != SCM_BOOL_F) return 1; return 0; }
// Common code for pyscm_PySCM_getattr() and pyscm_PySCM_setattr(): // Retrieve and return the 4-element vector corresponding to desired // attribute of the pyscm_PySCMObject. // Perform also validity checking and raise Python exception if // invalid. // Since it is needed later, also the SCM object, corresponding to the // pyscm_PySCMObject, is returned to the caller, put into 2-element // list together with the #:-keyword corresponding to name. static SCM retrieve_sattr_vector(pyscm_PySCMObject *self, char *name, SCM *sobj_keyword) { SCM shandle = scm_hashv_get_handle(pyscm_registration_hash,scm_long2num(self->ob_scm_index)); if (SCM_BOOLP(shandle) && SCM_EQ_P(SCM_BOOL_F,shandle)) { Py_FatalError("PySCM object lost its associated SCM object"); } // Now: // SCM_CADR(shandle) is the SCM object itself // SCM_CDDR(shandle) is the stemplate. SCM sattrshash = GET_ATTRS_HASH(SCM_CDDR(shandle)); if (SCM_EQ_P(SCM_BOOL_F,sattrshash)) { PyErr_SetString(PyExc_AttributeError, name); return(SCM_UNDEFINED); // Error return } // The object has attributes. Build the hash key (a keyword). size_t nlength = strlen(name); char *dashstr = malloc(nlength+2); dashstr[0] = '-'; dashstr[1] = '\0'; strncat(dashstr,name,nlength); SCM skeyword = scm_make_keyword_from_dash_symbol(scm_str2symbol(dashstr)); // !!! Do we have to free dashstr? // !!! Similar code is used also in pytoguile.c - review it. SCM sattr_vector_handle = scm_hashv_get_handle(sattrshash,skeyword); if (SCM_EQ_P(SCM_BOOL_F,sattr_vector_handle)) { // Missing attribute. How to deal with it? sattr_vector_handle = scm_hashv_get_handle(sattrshash,SCM_BOOL_F); if (SCM_EQ_P(SCM_BOOL_F,sattr_vector_handle)) { // Hash value corresponding to key #f is itself another #f, which // means that the object does not wish to exhibit to Python // unknown attributes. PyErr_SetString(PyExc_AttributeError, name); return(SCM_UNDEFINED); // Error return } // Otherwise, we'll use the hash value corresponding to #f as // a catch-all for all attributes not otherwise defined. } *sobj_keyword = scm_list_2(SCM_CADR(shandle),skeyword); return(SCM_CDR(sattr_vector_handle)); }
GameObjData* GameObjDataFactory::create (SCM symbol, SCM data) { /* if (Guile::equal_p(scm_str2symbol("tree"), symbol)) { return new TreeData (data); } else*/ if (Guile::equal_p(scm_str2symbol("tank"), symbol)) { std::cout << "GameObjDataFactory::create: not implemented" << std::endl; } else { std::cout << "GameObjDataFactory: Unknown symbol: " << std::flush; gh_display (symbol); gh_newline (); } return 0; }