The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
lua_formula_bridge.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#pragma once
16
17#include <functional>
18#include <memory>
19#include <string>
20
21struct lua_State;
22
23namespace wfl {
24 class formula;
25 class function_symbol_table;
26 class formula_debugger;
27 class formula_callable;
28 class variant;
29}
30
32
33 int intf_eval_formula(lua_State*);
34 int intf_compile_formula(lua_State*);
35 std::string register_metatables(lua_State*);
36
37 class fwrapper {
38 std::shared_ptr<wfl::formula> formula_ptr;
39 public:
40 fwrapper(const std::string& code);
41 std::string str() const;
42 wfl::variant evaluate(const wfl::formula_callable& variables, wfl::formula_debugger* fdb = nullptr) const;
43 };
44
45 using fpointer = std::unique_ptr<fwrapper, std::function<void(fwrapper*)>>;
46} // end namespace lua_formula_bridge
47lua_formula_bridge::fpointer luaW_check_formula(lua_State* L, int idx, bool allow_str);
wfl::variant evaluate(const wfl::formula_callable &variables, wfl::formula_debugger *fdb=nullptr) const
std::shared_ptr< wfl::formula > formula_ptr
lua_formula_bridge::fpointer luaW_check_formula(lua_State *L, int idx, bool allow_str)
Get a formula from the stack.
std::unique_ptr< fwrapper, std::function< void(fwrapper *)> > fpointer
std::string register_metatables(lua_State *)
int intf_compile_formula(lua_State *)
int intf_eval_formula(lua_State *)
Evaluates a formula in the formula engine.