The Battle for Wesnoth  1.19.0-dev
lua_formula_bridge.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
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 <memory>
18 #include <string>
19 
20 struct lua_State;
21 
22 namespace wfl {
23  class formula;
24  class function_symbol_table;
25  class formula_debugger;
26  class formula_callable;
27  class variant;
28 }
29 
30 namespace lua_formula_bridge {
31 
32  int intf_eval_formula(lua_State*);
33  int intf_compile_formula(lua_State*);
34  std::string register_metatables(lua_State*);
35 
36  class fwrapper {
37  std::shared_ptr<wfl::formula> formula_ptr;
38  public:
39  fwrapper(const std::string& code, wfl::function_symbol_table* functions = nullptr);
40  std::string str() const;
41  wfl::variant evaluate(const wfl::formula_callable& variables, wfl::formula_debugger* fdb = nullptr) const;
42  };
43 
44 } // end namespace lua_formula_bridge
wfl::variant evaluate(const wfl::formula_callable &variables, wfl::formula_debugger *fdb=nullptr) const
std::shared_ptr< wfl::formula > formula_ptr
fwrapper(const std::string &code, wfl::function_symbol_table *functions=nullptr)
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.
Definition: contexts.hpp:43