diff --git a/src/include/OSL/oslquery.h b/src/include/OSL/oslquery.h index a7960ac79d..75766374e0 100644 --- a/src/include/OSL/oslquery.h +++ b/src/include/OSL/oslquery.h @@ -97,6 +97,11 @@ class OSLQUERYPUBLIC OSLQuery { Parameter(Parameter&& src); const Parameter& operator=(const Parameter&); const Parameter& operator=(Parameter&&); + + /// Return the type as a string ("float", "color[7]", etc.) + std::string type_name() const; + /// Set the type as a string + void type_name(const std::string& typestring); }; /// OSLQuery methods diff --git a/src/liboslquery/oslquery.cpp b/src/liboslquery/oslquery.cpp index 1ea3effae2..9a741a5156 100644 --- a/src/liboslquery/oslquery.cpp +++ b/src/liboslquery/oslquery.cpp @@ -351,6 +351,22 @@ OSLQuery::Parameter::operator=(Parameter&& src) +std::string +OSLQuery::Parameter::type_name() const +{ + return type.c_str(); +} + + + +void +OSLQuery::Parameter::type_name(const std::string& typestring) +{ + type = TypeDesc(typestring); +} + + + OSLQuery::OSLQuery() {} diff --git a/src/liboslquery/py_osl.cpp b/src/liboslquery/py_osl.cpp index 56a2f70a2f..a4b904a913 100644 --- a/src/liboslquery/py_osl.cpp +++ b/src/liboslquery/py_osl.cpp @@ -26,6 +26,10 @@ declare_oslqueryparam(py::module& m) return PY_STR(p.name.string()); }) .def_readwrite("type", &Parameter::type) + .def_property( + "type_name", + [](const Parameter& p) { return PY_STR(p.type_name()); }, + [](Parameter& p, const std::string& t) { p.type_name(t); }) .def_readwrite("isoutput", &Parameter::isoutput) .def_readwrite("varlenarray", &Parameter::varlenarray) .def_readwrite("isstruct", &Parameter::isstruct) @@ -171,9 +175,6 @@ declare_oslquery(py::module& m) PYBIND11_MODULE(oslquery, m) { - // Force an OIIO module load so we have TypeDesc, among other things. - py::module oiio = py::module::import("OpenImageIO"); - // Global (OSL scope) functions and symbols m.attr("osl_version") = OSL_VERSION; m.attr("VERSION") = OSL_VERSION; diff --git a/testsuite/python-oslquery/src/test_oslquery.py b/testsuite/python-oslquery/src/test_oslquery.py index 720c9ad268..129155c05a 100755 --- a/testsuite/python-oslquery/src/test_oslquery.py +++ b/testsuite/python-oslquery/src/test_oslquery.py @@ -30,8 +30,8 @@ def printparam(p, indent=" ") : # as tuples. print (indent, "{}{} {} = {}".format( "output " if p.isoutput else "", - p.type, p.name, - "'{}'".format(p.value) if p.type == "string" else p.value)) + p.type_name, p.name, + "'{}'".format(p.value) if p.type_name == "string" else p.value)) if p.spacename : print (indent, " space:", p.spacename) # Metadata are themselves another tuple of Parameter objects hanging off