1 //
2 //
3 
4 #include "LuaSEXP.h"
5 
6 namespace scripting {
7 namespace api {
8 
lua_sexp_h(sexp::LuaSEXP * handle)9 lua_sexp_h::lua_sexp_h(sexp::LuaSEXP* handle) : sexp_handle(handle) {
10 }
lua_sexp_h()11 lua_sexp_h::lua_sexp_h() : sexp_handle(nullptr) {
12 }
isValid()13 bool lua_sexp_h::isValid() {
14 	return sexp_handle != nullptr;
15 }
16 
17 ADE_OBJ(l_LuaSEXP, lua_sexp_h, "LuaSEXP", "Lua SEXP handle");
18 
19 ADE_VIRTVAR(Action,
20 	l_LuaSEXP,
21 	"function(any... args) => void action",
22 	"The action of this SEXP",
23 	"function(any... args) => void action",
24 	"The action function or nil on error")
25 {
26 	lua_sexp_h lua_sexp;
27 	luacpp::LuaFunction action_arg;
28 	if (!ade_get_args(L, "o|u", l_LuaSEXP.Get(&lua_sexp), &action_arg)) {
29 		return ADE_RETURN_NIL;
30 	}
31 
32 	if (!lua_sexp.isValid()) {
33 		return ADE_RETURN_NIL;
34 	}
35 
36 	if (ADE_SETTING_VAR) {
37 		Assertion(action_arg.isValid(), "Action function reference must be valid!");
38 
39 		lua_sexp.sexp_handle->setAction(action_arg);
40 	}
41 
42 	auto action = lua_sexp.sexp_handle->getAction();
43 	return ade_set_args(L, "u", &action);
44 }
45 
46 }
47 }
48 
49