mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 17:48:46 -10:00
This add a system for adding generic instances of the DynamicSEXP class to the SEXP system. The only implementation at the moment is the LuaSEXP which is used by the mn.addSEXP lua API to allow Lua to add new SEXPs. Since this requires that FRED also runs lua scripts I added a mod table option to enable scripting in FRED. Since the current scripts are not built with FRED in mind it would likely break all these scripts if FRED would be opened with normal scripting enabled. This fixes #1320.
43 lines
913 B
C++
43 lines
913 B
C++
//
|
|
//
|
|
|
|
#include "LuaSEXP.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
lua_sexp_h::lua_sexp_h(sexp::LuaSEXP* handle) : sexp_handle(handle) {
|
|
}
|
|
lua_sexp_h::lua_sexp_h() : sexp_handle(nullptr) {
|
|
}
|
|
bool lua_sexp_h::isValid() {
|
|
return sexp_handle != nullptr;
|
|
}
|
|
|
|
ADE_OBJ(l_LuaSEXP, lua_sexp_h, "LuaSEXP", "Lua SEXP handle");
|
|
|
|
ADE_VIRTVAR(Action, l_LuaSEXP, "function action", "The action of this SEXP", "function", "The action function or nil on error") {
|
|
lua_sexp_h lua_sexp;
|
|
luacpp::LuaFunction action_arg;
|
|
if (!ade_get_args(L, "o|u", l_LuaSEXP.Get(&lua_sexp), &action_arg)) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
if (!lua_sexp.isValid()) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
Assertion(action_arg.isValid(), "Action function reference must be valid!");
|
|
|
|
lua_sexp.sexp_handle->setAction(action_arg);
|
|
}
|
|
|
|
auto action = lua_sexp.sexp_handle->getAction();
|
|
return ade_set_args(L, "u", &action);
|
|
}
|
|
|
|
}
|
|
}
|
|
|