def ApplyCommonRules(self, mb): # Common function added for getting the "PyObject" of an entity mb.member_functions('GetPySelf').exclude() ihandleentity = mb.class_('IHandleEntity') # All return values derived from IHandleEntity entity will be returned by value. # This ensures the converter is called testinherit = MatcherTestInheritClass(ihandleentity) decls = mb.calldefs(matchers.custom_matcher_t(testinherit)) decls.call_policies = call_policies.return_value_policy(call_policies.return_by_value) # All CBaseEntity related classes should have a custom call trait self.baseentcls = mb.class_('CBaseEntity' if self.isserver else 'C_BaseEntity') def ent_call_trait(type_): return '%(arg)s ? %(arg)s->GetPyHandle() : boost::python::object()' entclasses = mb.classes(self.TestCBaseEntity) for entcls in entclasses: entcls.custom_call_trait = ent_call_trait # All functions receiving an IHandleEntity argument should be converted def ihandleentity_call_trait(type_): return 'PyEntityFromEntityHandle( %(arg)s )' ihandleentity.custom_call_trait = ihandleentity_call_trait # Anything returning KeyValues should be returned by value so it calls the converter keyvalues = mb.class_('KeyValues') mb.calldefs(calldef_matcher_t(return_type=pointer_t(declarated_t(keyvalues))), allow_empty=True).call_policies = call_policies.return_value_policy(call_policies.return_by_value) mb.calldefs(calldef_matcher_t(return_type=pointer_t(const_t(declarated_t(keyvalues)))), allow_empty=True).call_policies = call_policies.return_value_policy(call_policies.return_by_value) # Anything returning a void pointer is excluded by default mb.calldefs(calldef_matcher_t(return_type=pointer_t(declarated_t(void_t()))), allow_empty=True).exclude() mb.calldefs(calldef_matcher_t(return_type=pointer_t(const_t(declarated_t(void_t())))), allow_empty=True).exclude()
def ApplyCommonRules(self, mb): # Common function added for getting the "PyObject" of an entity mb.mem_funs('GetPySelf').exclude() ihandleentity = mb.class_('IHandleEntity') # All return values derived from IHandleEntity entity will be returned by value. # This ensures the converter is called testinherit = MatcherTestInheritClass(ihandleentity) decls = mb.calldefs(matchers.custom_matcher_t(testinherit)) decls.call_policies = call_policies.return_value_policy(call_policies.return_by_value) # All CBaseEntity related classes should have a custom call trait self.baseentcls = mb.class_('CBaseEntity' if self.isserver else 'C_BaseEntity') def ent_call_trait(type_): return '%(arg)s ? %(arg)s->GetPyHandle() : boost::python::object()' entclasses = mb.classes(self.TestCBaseEntity) for entcls in entclasses: entcls.custom_call_trait = ent_call_trait # All functions receiving an IHandleEntity argument should be converted def ihandleentity_call_trait(type_): return 'PyEntityFromEntityHandle( %(arg)s )' ihandleentity.custom_call_trait = ihandleentity_call_trait # Anything returning KeyValues should be returned by value so it calls the converter keyvalues = mb.class_('KeyValues') mb.calldefs(matchers.calldef_matcher_t(return_type=pointer_t(declarated_t(keyvalues))), allow_empty=True).call_policies = call_policies.return_value_policy(call_policies.return_by_value) mb.calldefs(matchers.calldef_matcher_t(return_type=pointer_t(const_t(declarated_t(keyvalues)))), allow_empty=True).call_policies = call_policies.return_value_policy(call_policies.return_by_value) # Anything returning a void pointer is excluded by default mb.calldefs(matchers.calldef_matcher_t(return_type=pointer_t(declarated_t(void_t()))), allow_empty=True).exclude() mb.calldefs(matchers.calldef_matcher_t(return_type=pointer_t(const_t(declarated_t(void_t())))), allow_empty=True).exclude()
def renamed(scope, regex, repl): regex = re.compile(regex) sanitize = lambda s: re.sub(r'\W+', '', s) subfn = lambda match: repl.format(*list(map(sanitize, match.groups()))) f = custom_matcher_t(lambda decl: regex.match(decl.name)) for c in ns.find(scope, 'classes', [f]): c.rename(regex.sub(subfn, c.name)) yield c
def Parse(self, mb): self.novguilib = (self.settings.branch == 'swarm') # Exclude everything by default mb.decls().exclude() self.ParsePanelHandles(mb) self.ParsePanels(mb) self.ParsePanel(mb) self.ParseEditablePanel(mb) self.ParseFrame(mb) self.ScrollBar(mb) self.ParseAnimationController(mb) self.ParseTextEntry(mb) self.ParseMisc(mb) # Should already be included, but is for some reason not... mb.mem_funs('SetControlEnabled').include() # Anything that returns a Panel should be returned by Value to call the right converter testinherit = MatcherTestInheritClass(mb.class_('Panel')) decls = mb.calldefs(matchers.custom_matcher_t(testinherit)) decls.call_policies = call_policies.return_value_policy( call_policies.return_by_value) # All CBaseEntity related classes should have a custom call trait self.basepanelcls = mb.class_('Panel') def panel_call_trait(type_): return 'boost::python::object(*%(arg)s)' panelclasses = mb.classes(self.TestBasePanel) for panelclass in panelclasses: panelclass.custom_call_trait = panel_call_trait # Remove any protected function #mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() self.ParseImageClasses(mb) self.ApplyCommonRules(mb)
def Parse(self, mb): self.novguilib = (self.settings.branch == 'swarm') # Exclude everything by default mb.decls().exclude() self.ParsePanelHandles(mb) self.ParsePanels(mb) self.ParsePanel(mb) self.ParseEditablePanel(mb) self.ParseFrame(mb) self.ScrollBar(mb) self.ParseAnimationController(mb) self.ParseTextEntry(mb) #self.ParseMisc(mb) # Should already be included, but is for some reason not... mb.mem_funs('SetControlEnabled').include() # Anything that returns a Panel should be returned by Value to call the right converter testinherit = MatcherTestInheritClass(mb.class_('Panel')) decls = mb.calldefs(matchers.custom_matcher_t(testinherit)) decls.call_policies = call_policies.return_value_policy(call_policies.return_by_value) # All CBaseEntity related classes should have a custom call trait self.basepanelcls = mb.class_('Panel') def panel_call_trait(type_): return 'boost::python::object(*%(arg)s)' panelclasses = mb.classes(self.TestBasePanel) for panelclass in panelclasses: panelclass.custom_call_trait = panel_call_trait # Remove any protected function #mb.calldefs( matchers.access_type_matcher_t( 'protected' ) ).exclude() self.ParseImageClasses(mb) self.ApplyCommonRules(mb)