9 #include "LUAFunctions.h"
20 void filterLUA(
const AIPtr& entity) {
22 const std::string name =
"__meta_filter_" + _name;
23 lua_getfield(_s, LUA_REGISTRYINDEX, name.c_str());
24 #if AI_LUA_SANTITY > 0
25 if (lua_isnil(_s, -1)) {
26 ai_log_error(
"LUA filter: could not find lua userdata for %s", _name.c_str());
31 lua_getmetatable(_s, -1);
32 #if AI_LUA_SANTITY > 0
33 if (!lua_istable(_s, -1)) {
34 ai_log_error(
"LUA filter: userdata for %s doesn't have a metatable assigned", _name.c_str());
39 lua_getfield(_s, -1,
"filter");
40 if (!lua_isfunction(_s, -1)) {
41 ai_log_error(
"LUA filter: metatable for %s doesn't have the filter() function assigned", _name.c_str());
46 lua_getfield(_s, LUA_REGISTRYINDEX, name.c_str());
49 if (luaAI_pushai(_s, entity) == 0) {
52 #if AI_LUA_SANTITY > 0
53 if (!lua_isfunction(_s, -3)) {
54 ai_log_error(
"LUA filter: expected to find a function on stack -3");
57 if (!lua_isuserdata(_s, -2)) {
58 ai_log_error(
"LUA filter: expected to find the userdata on -2");
61 if (!lua_isuserdata(_s, -1)) {
62 ai_log_error(
"LUA filter: second parameter should be the ai");
66 const int error = lua_pcall(_s, 2, 0, 0);
68 ai_log_error(
"LUA filter script: %s", lua_isstring(_s, -1) ? lua_tostring(_s, -1) :
"Unknown Error");
72 lua_pop(_s, lua_gettop(_s));
82 _s(s), _type(typeStr) {
85 inline const std::string& type()
const {
90 return std::make_shared<LUAFilter>(_type, ctx->parameters, _s);
94 LUAFilter(
const std::string& name,
const std::string& parameters, lua_State* s) :
95 IFilter(name, parameters), _s(s) {
101 void filter(
const AIPtr& entity)
override {
#define ai_log_error(...)
Logging macro to provide your own loggers.
Definition: Types.h:23
Definition: AIFactories.h:89
Definition: LUAFilter.h:16
Definition: AIFactories.h:34
Definition: LUAFilter.h:76