File: content.cpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (25 lines) | stat: -rw-r--r-- 923 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "content.hpp"
#include "element.hpp"

namespace LuaUi
{
    sol::protected_function loadContentConstructor(LuaUtil::LuaState* state)
    {
        sol::protected_function loader = state->loadInternalLib("content");
        sol::set_environment(state->newInternalLibEnvironment(), loader);
        sol::table metatable = LuaUtil::LuaState::throwIfError(loader()).get<sol::table>();
        if (metatable["new"].get_type() != sol::type::function)
            throw std::logic_error("Expected function");
        return metatable["new"].get<sol::protected_function>();
    }

    bool isValidContent(const sol::object& object)
    {
        if (object.is<Element>())
            return true;
        if (object.get_type() != sol::type::table)
            return false;
        sol::table table = object;
        return table.traverse_get<sol::optional<bool>>(sol::metatable_key, "__Content").value_or(false);
    }
}