Class Context

Synopsis

#include <Source/Falcor/Utils/Scripting/Scripting.h>

class Context

Description

No description yet.

Structures

ObjectDesc

Methods

containsObject
getObject
getObjects
setObject

Source

Lines 45-95 in Source/Falcor/Utils/Scripting/Scripting.h.

class Context
{
public:
    template<typename T>
    struct ObjectDesc
    {
        ObjectDesc(const std::string& name_, const T& obj_) : name(name_), obj(obj_) {}
        operator const T&() const { return obj; }
        std::string name;
        T obj;
    };
    template<typename T>
    std::vector<ObjectDesc<T>> getObjects()
    {
        std::vector<ObjectDesc<T>> v;
        for (const auto& l : mLocals)
        {
            try
            {
                if(!l.second.is_none())
                {
                    v.push_back(ObjectDesc<T>(l.first.cast<std::string>(), l.second.cast<T>()));
                }
            }
            catch (const std::exception&) {}
        }
        return v;
    }
    template<typename T>
    void setObject(const std::string& name, T obj)
    {
        mLocals[name.c_str()] = obj;
    }
    template<typename T>
    T getObject(const std::string& name) const
    {
        return mLocals[name.c_str()].cast<T>();
    }
    bool containsObject(const std::string& name) const
    {
        return mLocals.contains(name.c_str());
    }
private:
    friend class Scripting;
    pybind11::dict mLocals;
};





Add Discussion as Guest

Log in