diff --git a/devtools/director-generate-xobj-stub.py b/devtools/director-generate-xobj-stub.py index 135dab0d3d6..8e96ed642a4 100755 --- a/devtools/director-generate-xobj-stub.py +++ b/devtools/director-generate-xobj-stub.py @@ -67,7 +67,7 @@ namespace Director {{ class {xobject_class} : public Object<{xobject_class}> {{ public: - {xobject_class}(ObjectType objType); + {xobject_class}(ObjectType objType);{xtra_props_h} }}; namespace {xobj_class} {{ @@ -132,11 +132,13 @@ static BuiltinProto xlibBuiltins[] = {{ {xobject_class}::{xobject_class}(ObjectType ObjectType) :Object<{xobject_class}>("{name}") {{ _objType = ObjectType; -}} +}}{xtra_props} void {xobj_class}::open(ObjectType type, const Common::Path &path) {{ {xobject_class}::initMethods(xlibMethods); {xobject_class} *xobj = new {xobject_class}(type); + if (type == kXtraObj) + g_lingo->_openXtras.push_back(xlibName); g_lingo->exposeXObject(xlibName, xobj); g_lingo->initBuiltIns(xlibBuiltins); }} @@ -162,6 +164,26 @@ XLIB_NEW_TEMPLATE = """void {xobj_class}::m_new(int nargs) {{ }}""" +# XTRA PROPS TEMPLATE and Header contains extra newline at the beginning. +# This keeps the newlines correct when `TEMPLATE` is used for xlibs. +XTRA_PROPS_TEMPLATE = """ + +bool {xobject_class}::hasProp(const Common::String &propName) {{ + return (propName == "name"); +}} + +Datum {xobject_class}::getProp(const Common::String &propName) {{ + if (propName == "name") + return Datum({xobj_class}::xlibName); + warning("{xobj_class}::getProp: unknown property '%s'", propName.c_str()); + return Datum(); +}}""" + +XTRA_PROPS_H = """ + + bool hasProp(const Common::String &propName) override; + Datum getProp(const Common::String &propName) override;""" + XCMD_TEMPLATE_H = ( LEGAL @@ -718,6 +740,7 @@ def generate_xobject_stubs( for x in meths ] ), + xtra_props="", xobj_new=XLIB_NEW_TEMPLATE.format(xobj_class=xobj_class), xobj_stubs="\n".join( [ @@ -742,6 +765,7 @@ def generate_xobject_stubs( slug_upper=slug.upper(), xobject_class=xobject_class, xobj_class=xobj_class, + xtra_props_h="", methlist="\n".join([TEMPLATE_HEADER_METH.format(**x) for x in meths]), ) if dry_run: @@ -888,6 +912,8 @@ def generate_xtra_stubs( director_version=director_version, methtype="HBLTIN", ) for x in meths if x["functype"] == "toplevel"]), + xtra_props=XTRA_PROPS_TEMPLATE.format(xobj_class=xobj_class, + xobject_class=xobject_class), xobj_new=XLIB_NEW_TEMPLATE.format(xobj_class=xobj_class), xobj_stubs="\n".join( [ @@ -910,6 +936,7 @@ def generate_xtra_stubs( slug_upper=slug.upper(), xobject_class=xobject_class, xobj_class=xobj_class, + xtra_props_h=XTRA_PROPS_H, methlist="\n".join([TEMPLATE_HEADER_METH.format(**x) for x in meths]), ) if dry_run: