void AnnotationDefinition::Define(NodePtr node, TypeCode type, const ReasonPtr & reason) { ElementPtr member = node->GetElement(); if (!!member) { AnnotationDefinitionPtr existingDef = boost::dynamic_pointer_cast<AnnotationDefinition>(member); if (!existingDef) { std::stringstream ss; ss << "Attempt to define previously defined Node " << node->GetFullName() << " as an Annotation."; throw ModelInconsistencyException(existingDef->GetReasonCreated(), reason, ss.str()); } else { if (existingDef->GetTypeCode() == type) { // Phew! Old def is the same as this one. return; } std::stringstream ss; ss << "Attempt to redefine Annotation " << node->GetFullName() << " with value type of " << existingDef->GetAnnotationTypeName() << " as value type " << getAnnotationTypeName(type); throw ModelInconsistencyException(existingDef->GetReasonCreated(), reason, ss.str()); } } // end !!member Create(node, type, reason); }
int NodeLuaMetaData::Index(lua_State * L, NodePtr & ptr, const std::string & index) { /*if (index == "FindOrCreateClass") { lua_pushcfunction(L, NodeLuaFunctions::FindOrCreateClass); return 1; } else if (index == "FindOrCreateNamespace") { lua_pushcfunction(L, NodeLuaFunctions::FindOrCreateNamespace); return 1; } else*/ if (index == "AdoptedHome") { NodePtr adoptedHome = ptr->GetAdoptedHome(); if (!adoptedHome) { lua_pushnil(L); } else { NodeLuaMetaData::PutInstanceOnStack(L, adoptedHome); } } else if (index == "Annotations") { AnnotationTable & table = ptr->GetAnnotations(); AnnotationTablePtr tPtr(&table); AnnotationTableLuaMetaData::PutInstanceOnStack(L, tPtr); } else if (index == "Find") { lua_pushcfunction(L, NodeLuaFunctions::Find); return 1; } else if (index == "FindOrCreate") { lua_pushcfunction(L, NodeLuaFunctions::FindOrCreate); return 1; } else if (index == "FullName") { lua_pushlstring(L, ptr->GetFullName().c_str(), ptr->GetFullName().size()); } else if (index == "GetOperatorName") { lua_pushcfunction(L, NodeLuaFunctions::GetOperatorName); } else if (index == "GetPrettyFullName") { lua_pushcfunction(L, NodeLuaFunctions::PrettyFullName); } else if (index == "HFilePath") { FileNamePtr fileName = ptr->GetHFilePath(); if (!fileName) { lua_pushnil(L); } else { FileNameLuaMetaData::PutInstanceOnStack(L, ptr->GetHFilePath()); } } else if (index == "IsOperator") { lua_pushboolean(L, ptr->IsOperator()); } else if (index == "IsRoot") { lua_pushboolean(L, ptr->IsRoot()); return 1; } else if (index == "Children") { // Put a lua pointer for this Node object on the Lua stack, // but associate it with a different meta table. createNodePtrUserData(L, ptr); luaL_getmetatable(L, MEMBERSPROPERTY_METATABLENAME); lua_setmetatable(L, -2); return 1; } else if (index == "Element") { ElementLuaMetaData::PutInstanceOnStack(L, ptr->GetElement()); } else if (index == "Member") { ElementLuaMetaData::PutInstanceOnStack(L, ptr->GetElement()); //return luaL_error(L, // "Member is the old name, please switch to \"Element\"."); } else if (index == "Name") { lua_pushlstring(L, ptr->GetName().c_str(), ptr->GetName().length()); } else if (index == "Node") { NodePtr scope = ptr->GetNode(); NodeLuaMetaData::PutInstanceOnStack(L, scope); } else if (index == "ParseComplexName") { lua_pushcfunction(L, NodeLuaFunctions::ParseComplexName); } else if (index == "SetHFilePath") { lua_pushcfunction(L, NodeLuaFunctions::SetHFilePath); } else if (index == "TypeName") { lua_pushstring(L, ptr->GetTypeName()); } else { lua_pushnil(L); } return 1; }