mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-09 04:49:39 -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.
88 lines
2.5 KiB
C++
88 lines
2.5 KiB
C++
#ifndef LUAUTIL_H
|
|
#define LUAUTIL_H
|
|
#pragma once
|
|
|
|
#include "LuaHeaders.h"
|
|
#include "LuaException.h"
|
|
#include "LuaConvert.h"
|
|
#include "LuaReference.h"
|
|
|
|
#include "scripting/ade.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
namespace luacpp {
|
|
/**
|
|
* @brief Contains functions to convert C++ values to and from lua values.
|
|
*
|
|
* Currently the following types are supported:
|
|
* - `double`
|
|
* - `float`
|
|
* - `int`
|
|
* - `std::string`
|
|
* - `const char*` (only for pushing as using the pointer after it was removed from the stack is dangerous)
|
|
* - `bool`
|
|
* - `lua_CFunction`
|
|
* - `LuaTable` (only pop, use LuaValue version for pushing)
|
|
* - `LuaFunction` (only pop, use LuaValue version for pushing)
|
|
* - `LuaValue` (this will reference any value at the specified poition)
|
|
*/
|
|
namespace convert {
|
|
|
|
namespace internal {
|
|
bool isValidIndex(lua_State* state, int index);
|
|
}
|
|
|
|
void pushValue(lua_State* luaState, const double& value);
|
|
|
|
void pushValue(lua_State* luaState, const float& value);
|
|
|
|
void pushValue(lua_State* luaState, const int& value);
|
|
|
|
void pushValue(lua_State* luaState, const size_t& value);
|
|
|
|
void pushValue(lua_State* luaState, const std::string& value);
|
|
|
|
void pushValue(lua_State* luaState, const char* value);
|
|
|
|
void pushValue(lua_State* luaState, const bool& value);
|
|
|
|
void pushValue(lua_State* luaState, const lua_CFunction& value);
|
|
|
|
void pushValue(lua_State* L, const scripting::ade_odata& value);
|
|
|
|
/**
|
|
* @brief Convenience function for string literals
|
|
*
|
|
* @param luaState The lua_State to push the values to
|
|
* @param value The value which should be pushed.
|
|
* @return void
|
|
*/
|
|
template<size_t N>
|
|
inline void pushValue(lua_State* luaState, const char(& value)[N]) {
|
|
pushValue(luaState, (const char*)value);
|
|
}
|
|
|
|
|
|
bool popValue(lua_State* luaState, float& target, int stackposition = -1, bool remove = true);
|
|
|
|
bool popValue(lua_State* luaState, double& target, int stackposition = -1, bool remove = true);
|
|
|
|
bool popValue(lua_State* luaState, int& target, int stackposition = -1, bool remove = true);
|
|
|
|
bool popValue(lua_State* luaState, size_t& target, int stackposition = -1, bool remove = true);
|
|
|
|
bool popValue(lua_State* luaState, std::string& target, int stackposition = -1, bool remove = true);
|
|
|
|
bool popValue(lua_State* luaState, bool& target, int stackposition = -1, bool remove = true);
|
|
|
|
bool popValue(lua_State* luaState, lua_CFunction& target, int stackposition = -1, bool remove = true);
|
|
|
|
bool popValue(lua_State* L, scripting::ade_odata& od, int stackposition = -1, bool remove = true);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
#endif
|