aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/script.cpp
blob: 13d7cf52c9bbd0d3cb0e567465363c7ef556d8ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "engine/script.hpp"
#include <cstdio>

ScriptEngine::ScriptEngine() {
    lua_.open_libraries(sol::lib::base, sol::lib::table, sol::lib::string,
                        sol::lib::math, sol::lib::os);
}

bool ScriptEngine::run_file(const std::string& path) {
    sol::protected_function_result r =
        lua_.safe_script_file(path, sol::script_pass_on_error);
    if (!r.valid()) {
        sol::error err = r;
        fprintf(stderr, "Lua error (%s): %s\n", path.c_str(), err.what());
        return false;
    }
    return true;
}