mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-08 12:39:49 -06:00
Simplify specification of properties
This commit is contained in:
@@ -30,108 +30,100 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat2x2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat2x2 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat2x2(0);
|
||||
}
|
||||
else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat2x2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat2x2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat2x2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat2x2>::value * ghoul::glm_cols<glm::dmat2x2>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat2x2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat2x2 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x2>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2Property, glm::dmat2x2, glm::dmat2x2(0),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x2(
|
||||
0.01, 0.01,
|
||||
0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat2Property,
|
||||
glm::dmat2x2,
|
||||
glm::dmat2x2(0),
|
||||
glm::dmat2x2(nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()),
|
||||
glm::dmat2x2(nl::max(), nl::max(), nl::max(), nl::max()),
|
||||
glm::dmat2x2(0.01, 0.01, 0.01, 0.01),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,112 +30,108 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat2x3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat2x3 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat2x3(0);
|
||||
}
|
||||
else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat2x3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat2x3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat2x3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat2x3>::value * ghoul::glm_cols<glm::dmat2x3>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat2x3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat2x3 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x3>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x3Property, glm::dmat2x3, glm::dmat2x3(0),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat2x3Property,
|
||||
glm::dmat2x3,
|
||||
glm::dmat2x3(0),
|
||||
glm::dmat2x3(
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat2x3(
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat2x3(0.01, 0.01, 0.01, 0.01, 0.01, 0.01),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,116 +30,110 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat2x4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat2x4 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat2x4(0);
|
||||
}
|
||||
else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat2x4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat2x4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat2x4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat2x4>::value * ghoul::glm_cols<glm::dmat2x4>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat2x4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat2x4 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat2x4>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat2x4Property, glm::dmat2x4, glm::dmat2x4(0),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat2x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat2x4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat2x4Property,
|
||||
glm::dmat2x4,
|
||||
glm::dmat2x4(0),
|
||||
glm::dmat2x4(
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat2x4(
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat2x4(0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,119 +30,114 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat3x3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat3x3 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
int type = lua_type(state, -1);
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat3x3(0);
|
||||
}
|
||||
else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat3x3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat3x3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat3x3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat3x3>::value * ghoul::glm_cols<glm::dmat3x3>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat3x3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat3x3 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x3>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3Property, glm::dmat3x3, glm::dmat3x3(0),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat3Property,
|
||||
glm::dmat3x3,
|
||||
glm::dmat3x3(0),
|
||||
glm::dmat3x3(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat3x3(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,112 +30,109 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat3x2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat3x2 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat3x2(0);
|
||||
}
|
||||
else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat3x2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat3x2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat3x2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat3x2>::value * ghoul::glm_cols<glm::dmat3x2>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat3x2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat3x2 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x2>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x2Property, glm::dmat3x2, glm::dmat3x2(0),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat3x2Property,
|
||||
glm::dmat3x2,
|
||||
glm::dmat3x2(0),
|
||||
glm::dmat3x2(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat3x2(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,125 +30,116 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat3x4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat3x4 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat3x4(0);
|
||||
}
|
||||
else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat3x4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
glm::dmat3x4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat3x4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat3x4>::value * ghoul::glm_cols<glm::dmat3x4>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat3x4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat3x4 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat3x4>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat3x4Property, glm::dmat3x4, glm::dmat3x4(0),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat3x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat3x4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat3x4Property,
|
||||
glm::dmat3x4,
|
||||
glm::dmat3x4(0),
|
||||
glm::dmat3x4(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat3x4(
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,134 +30,115 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat4x4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat4x4 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat4x4(0);
|
||||
}
|
||||
else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat4x4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat4x4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat4x4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat4x4>::value * ghoul::glm_cols<glm::dmat4x4>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat4x4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat4x4 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x4>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4Property, glm::dmat4x4, glm::dmat4x4(0),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat4Property,
|
||||
glm::dmat4x4,
|
||||
glm::dmat4x4(0),
|
||||
glm::dmat4x4(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat4x4(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,116 +30,108 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat4x2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat4x2 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat4x2(0);
|
||||
} else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat4x2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat4x2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat4x2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat4x2>::value * ghoul::glm_cols<glm::dmat4x2>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat4x2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat4x2 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x2>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x2Property, glm::dmat4x2, glm::dmat4x2(0),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat4x2Property,
|
||||
glm::dmat4x2,
|
||||
glm::dmat4x2(0),
|
||||
glm::dmat4x2(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat4x2(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,125 +30,111 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dmat4x3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dmat4x3 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dmat4x3(0);
|
||||
} else {
|
||||
result[i][j] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dmat4x3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
|
||||
lua_pushnumber(state, value[i][j]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dmat4x3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dmat4x3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::dmat4x3>::value * ghoul::glm_cols<glm::dmat4x3>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::dmat4x3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dmat4x3 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::dmat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::dmat4x3>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] = lua_tonumber(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<double>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, value[i][j]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DMat4x3Property, glm::dmat4x3, glm::dmat4x3(0),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::lowest()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max(),
|
||||
numeric_limits<double>::max()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dmat4x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dmat4x3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DMat4x3Property,
|
||||
glm::dmat4x3,
|
||||
glm::dmat4x3(0),
|
||||
glm::dmat4x3(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::dmat4x3(
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01,
|
||||
0.01, 0.01, 0.01, 0.01
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,109 +30,109 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::mat2x2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat2x2 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat2x2(0);
|
||||
} else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat2x2::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat2x2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat2x2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat2x2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat2x2>::value * ghoul::glm_cols<glm::mat2x2>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat2x2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat2x2 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x2>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2Property, glm::mat2x2, glm::mat2x2(0),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x2(
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat2Property,
|
||||
glm::mat2x2,
|
||||
glm::mat2x2(0),
|
||||
glm::mat2x2(
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat2x2(
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max()
|
||||
),
|
||||
glm::mat2x2(
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -32,111 +32,112 @@
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace {
|
||||
|
||||
glm::mat2x3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat2x3 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat2x3(0);
|
||||
}
|
||||
else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat2x3::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat2x3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat2x3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat2x3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat2x3>::value * ghoul::glm_cols<glm::mat2x3>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat2x3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat2x3 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x3>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x3Property, glm::mat2x3, glm::mat2x3(0),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat2x3Property,
|
||||
glm::mat2x3,
|
||||
glm::mat2x3(0),
|
||||
glm::mat2x3(
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat2x3(
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max()
|
||||
),
|
||||
glm::mat2x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,117 +30,116 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::mat2x4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat2x4 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat2x4(0);
|
||||
}
|
||||
else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat2x4::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat2x4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat2x4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat2x4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat2x4>::value * ghoul::glm_cols<glm::mat2x4>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat2x4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat2x4 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat2x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat2x4>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat2x4Property, glm::mat2x4, glm::mat2x4(0),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat2x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat2x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat2x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat2x4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat2x4Property,
|
||||
glm::mat2x4,
|
||||
glm::mat2x4(0),
|
||||
glm::mat2x4(
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat2x4(
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max(),
|
||||
nl::max(), nl::max()
|
||||
),
|
||||
glm::mat2x4(
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f,
|
||||
0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,120 +30,112 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::mat3x3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat3x3 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat3x3(0);
|
||||
} else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat3x3::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat3x3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat3x3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat3x3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat3x3>::value * ghoul::glm_cols<glm::mat3x3>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat3x3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat3x3 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x3>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3Property, glm::mat3x3, glm::mat3x3(0),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat3Property,
|
||||
glm::mat3x3,
|
||||
glm::mat3x3(0),
|
||||
glm::mat3x3(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat3x3(
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::mat3x3(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,113 +30,109 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::mat3x2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat3x2 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat3x2(0);
|
||||
} else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat3x2::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat3x2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat3x2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat3x2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat3x2>::value * ghoul::glm_cols<glm::mat3x2>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat3x2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat3x2 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x2>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x2Property, glm::mat3x2, glm::mat3x2(0),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x2(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat3x2Property,
|
||||
glm::mat3x2,
|
||||
glm::mat3x2(0),
|
||||
glm::mat3x2(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat3x2(
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::mat3x2(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,126 +30,115 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::mat3x4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat3x4 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat3x4(0);
|
||||
} else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat3x4::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat3x4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat3x4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat3x4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat3x4>::value * ghoul::glm_cols<glm::mat3x4>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat3x4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat3x4 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat3x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat3x4>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat3x4Property, glm::mat3x4, glm::mat3x4(0),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat3x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat3x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat3x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat3x4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat3x4Property,
|
||||
glm::mat3x4,
|
||||
glm::mat3x4(0),
|
||||
glm::mat3x4(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat3x4(
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::mat3x4(
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -32,133 +32,115 @@
|
||||
|
||||
using std::numeric_limits;
|
||||
|
||||
namespace {
|
||||
|
||||
glm::mat4x4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat4x4 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat4x4(0);
|
||||
} else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat4x4::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat4x4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat4x4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat4x4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat4x4>::value * ghoul::glm_cols<glm::mat4x4>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat4x4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat4x4 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x4>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x4>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4Property, glm::mat4x4, glm::mat4x4(0),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x4(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat4Property,
|
||||
glm::mat4x4,
|
||||
glm::mat4x4(0),
|
||||
glm::mat4x4(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat4x4(
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::mat4x4(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,117 +30,109 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::mat4x2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat4x2 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat4x2(0);
|
||||
} else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat4x2::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat4x2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat4x2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat4x2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat4x2>::value * ghoul::glm_cols<glm::mat4x2>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat4x2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat4x2 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x2>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x2>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x2Property, glm::mat4x2, glm::mat4x2(0),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x2(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x2(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat4x2Property,
|
||||
glm::mat4x2,
|
||||
glm::mat4x2(0),
|
||||
glm::mat4x2(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat4x2(
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::mat4x2(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,126 +30,112 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::mat4x3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::mat4x3 result;
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
|
||||
lua_getfield(state, -1, std::to_string(number).c_str());
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::mat4x3(0);
|
||||
} else {
|
||||
result[i][j]
|
||||
= static_cast<glm::mat4x3::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::mat4x3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::mat4x3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::mat4x3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() !=
|
||||
(ghoul::glm_rows<glm::mat4x3>::value * ghoul::glm_cols<glm::mat4x3>::value))
|
||||
{
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
int number = 0;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
|
||||
std::stringstream s(tokens[number]);
|
||||
glm::mat4x3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i][j] = v;
|
||||
++number;
|
||||
}
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::mat4x3 inValue) {
|
||||
outValue = "";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<glm::mat4x3>::value; ++i) {
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<glm::mat4x3>::value; ++j) {
|
||||
outValue += std::to_string(inValue[i][j]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_getfield(state, -1, std::to_string(number).c_str()); \
|
||||
if (lua_isnumber(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i][j] \
|
||||
= static_cast<__TYPE__::value_type>(lua_tonumber(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
using nl = std::numeric_limits<float>;
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i][j])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != \
|
||||
(ghoul::glm_rows<__TYPE__>::value * ghoul::glm_cols<__TYPE__>::value)) \
|
||||
{ \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
int number = 0; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
std::stringstream s(tokens[number]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i][j] = v; \
|
||||
++number; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = ""; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_cols<__TYPE__>::value; ++i) { \
|
||||
for (glm::length_t j = 0; j < ghoul::glm_rows<__TYPE__>::value; ++j) { \
|
||||
outValue += std::to_string(inValue[i][j]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Mat4x3Property, glm::mat4x3, glm::mat4x3(0),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::lowest()
|
||||
),
|
||||
glm::mat4x3(
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max(),
|
||||
numeric_limits<float>::max()
|
||||
),
|
||||
glm::mat4x3(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::mat4x3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::mat4x3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Mat4x3Property,
|
||||
glm::mat4x3,
|
||||
glm::mat4x3(0),
|
||||
glm::mat4x3(
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest(),
|
||||
nl::lowest(), nl::lowest(), nl::lowest(), nl::lowest()
|
||||
),
|
||||
glm::mat4x3(
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max(),
|
||||
nl::max(), nl::max(), nl::max(), nl::max()
|
||||
),
|
||||
glm::mat4x3(
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f,
|
||||
0.01f, 0.01f, 0.01f, 0.01f
|
||||
),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,38 +29,53 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
|
||||
bool fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isboolean(state, -1) == 1);
|
||||
if (success) {
|
||||
return lua_toboolean(state, -1) == 1;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, bool value) {
|
||||
lua_pushboolean(state, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
bool v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, bool inValue) {
|
||||
outValue = inValue ? "true" : "false";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BoolProperty, bool, false,
|
||||
[](lua_State* state, bool& success) -> bool {
|
||||
success = (lua_isboolean(state, -1) == 1);
|
||||
if (success) {
|
||||
return lua_toboolean(state, -1) == 1;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
[](lua_State* state, bool value) -> bool {
|
||||
lua_pushboolean(state, value);
|
||||
return true;
|
||||
},
|
||||
[](std::string val, bool& success) -> bool {
|
||||
std::stringstream s(val);
|
||||
bool v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
},
|
||||
[](std::string& outValue, bool inValue) -> bool {
|
||||
outValue = inValue ? "true" : "false";
|
||||
return true;
|
||||
},
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(
|
||||
BoolProperty,
|
||||
bool,
|
||||
false,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TBOOLEAN
|
||||
)
|
||||
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
char fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<char>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return char(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, char value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
char fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
char v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, char inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(CharProperty, char, char(0),
|
||||
numeric_limits<char>::lowest(),
|
||||
numeric_limits<char>::max(), char(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(char, char(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(char, char(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(char),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
CharProperty,
|
||||
char,
|
||||
char(0),
|
||||
std::numeric_limits<char>::lowest(),
|
||||
std::numeric_limits<char>::max(),
|
||||
char(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
double fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return lua_tonumber(state, -1);
|
||||
}
|
||||
else {
|
||||
return 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, double value) {
|
||||
lua_pushnumber(state, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
double fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
double v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, double inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return lua_tonumber(state, -1); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, value); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DoubleProperty, double, 0.0,
|
||||
numeric_limits<double>::lowest(),
|
||||
numeric_limits<double>::max(), 0.01,
|
||||
DEFAULT_FROM_LUA_LAMBDA(double, double(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(double),
|
||||
DEFAULT_FROM_STRING_LAMBDA(double, double(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(double),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DoubleProperty,
|
||||
double,
|
||||
0.0,
|
||||
std::numeric_limits<double>::lowest(),
|
||||
std::numeric_limits<double>::max(),
|
||||
0.01,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
float fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<float>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, float value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
float fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
float v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, float inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(FloatProperty, float, 0.f,
|
||||
numeric_limits<float>::lowest(),
|
||||
numeric_limits<float>::max(), 0.01f,
|
||||
DEFAULT_FROM_LUA_LAMBDA(float, float(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(float),
|
||||
DEFAULT_FROM_STRING_LAMBDA(float, float(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(float),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
FloatProperty,
|
||||
float,
|
||||
0.f,
|
||||
std::numeric_limits<float>::lowest(),
|
||||
std::numeric_limits<float>::max(),
|
||||
0.01f,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,53 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
int fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<int>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, int value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
int fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
int v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, int inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IntProperty, int, 0, numeric_limits<int>::lowest(),
|
||||
numeric_limits<int>::max(), 1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(int, 0),
|
||||
DEFAULT_TO_LUA_LAMBDA(int),
|
||||
DEFAULT_FROM_STRING_LAMBDA(int, 0),
|
||||
DEFAULT_TO_STRING_LAMBDA(int),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
IntProperty,
|
||||
int,
|
||||
0,
|
||||
std::numeric_limits<int>::lowest(),
|
||||
std::numeric_limits<int>::max(),
|
||||
1,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
long double fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<long double>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0l;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, long double value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
long double fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
long double v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, long double inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongDoubleProperty, long double, 0l,
|
||||
numeric_limits<long double>::lowest(),
|
||||
numeric_limits<long double>::max(), 0.01l,
|
||||
DEFAULT_FROM_LUA_LAMBDA(long double, 0l),
|
||||
DEFAULT_TO_LUA_LAMBDA(long double),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long double, 0l),
|
||||
DEFAULT_TO_STRING_LAMBDA(long double),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
LongDoubleProperty,
|
||||
long double,
|
||||
0l,
|
||||
std::numeric_limits<long double>::lowest(),
|
||||
std::numeric_limits<long double>::max(),
|
||||
0.01l,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
long long fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<long long>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, long long value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
long long fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
long long v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, long long inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongLongProperty, long long, 0,
|
||||
numeric_limits<long long>::lowest(),
|
||||
numeric_limits<long long>::max(), 1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(long long, 0),
|
||||
DEFAULT_TO_LUA_LAMBDA(long long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long long, 0),
|
||||
DEFAULT_TO_STRING_LAMBDA(long long),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
LongLongProperty,
|
||||
long long,
|
||||
0,
|
||||
std::numeric_limits<long long>::lowest(),
|
||||
std::numeric_limits<long long>::max(),
|
||||
1,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
long fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<long>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, long value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
long fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
long v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, long inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(LongProperty, long, long(0),
|
||||
numeric_limits<long>::lowest(),
|
||||
numeric_limits<long>::max(), long(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(long, long(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(long, long(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(long),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
LongProperty,
|
||||
long,
|
||||
long(0),
|
||||
std::numeric_limits<long>::lowest(),
|
||||
std::numeric_limits<long>::max(),
|
||||
long(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
short fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<short>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, short value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
short fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
short v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, short inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ShortProperty, short, short(0),
|
||||
numeric_limits<short>::lowest(),
|
||||
numeric_limits<short>::max(), short(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(short, short(0)),
|
||||
DEFAULT_TO_LUA_LAMBDA(short),
|
||||
DEFAULT_FROM_STRING_LAMBDA(short, short(0)),
|
||||
DEFAULT_TO_STRING_LAMBDA(short),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
ShortProperty,
|
||||
short,
|
||||
short(0),
|
||||
std::numeric_limits<short>::lowest(),
|
||||
std::numeric_limits<short>::max(),
|
||||
short(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
signed char fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<signed char>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, signed char value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
signed char fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
signed char v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, signed char inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(SignedCharProperty, signed char, 0,
|
||||
numeric_limits<signed char>::lowest(),
|
||||
numeric_limits<signed char>::max(), 0,
|
||||
DEFAULT_FROM_LUA_LAMBDA(signed char, 0),
|
||||
DEFAULT_TO_LUA_LAMBDA(signed char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(signed char, 0),
|
||||
DEFAULT_TO_STRING_LAMBDA(signed char),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
SignedCharProperty,
|
||||
signed char,
|
||||
0,
|
||||
std::numeric_limits<signed char>::lowest(),
|
||||
std::numeric_limits<signed char>::max(),
|
||||
0,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
unsigned char fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<unsigned char>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, unsigned char value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned char fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
unsigned char v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, unsigned char inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UCharProperty, unsigned char, 0,
|
||||
numeric_limits<unsigned char>::lowest(),
|
||||
numeric_limits<unsigned char>::max(), 1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned char, 0),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned char),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned char, 0),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned char),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
UCharProperty,
|
||||
unsigned char,
|
||||
0,
|
||||
std::numeric_limits<unsigned char>::lowest(),
|
||||
std::numeric_limits<unsigned char>::max(),
|
||||
1,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
unsigned int fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<unsigned int>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, unsigned int value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned int fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
unsigned int v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, unsigned int inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UCharProperty, unsigned int, 0,
|
||||
numeric_limits<unsigned int>::lowest(),
|
||||
numeric_limits<unsigned int>::max(), 1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned int, 0),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned int),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned int, 0),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned int),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
UCharProperty,
|
||||
unsigned int,
|
||||
0,
|
||||
std::numeric_limits<unsigned int>::lowest(),
|
||||
std::numeric_limits<unsigned int>::max(),
|
||||
1,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
unsigned long long fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<unsigned long long>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0ull;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, unsigned long long value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned long long fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
unsigned long long v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, unsigned long long inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ULongLongProperty, unsigned long long, 1ull,
|
||||
numeric_limits<unsigned long long>::lowest(),
|
||||
numeric_limits<unsigned long long>::max(), 1ull,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned long long, 0ull),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned long long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned long long, 0ull),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned long long),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
ULongLongProperty,
|
||||
unsigned long long,
|
||||
1ull,
|
||||
std::numeric_limits<unsigned long long>::lowest(),
|
||||
std::numeric_limits<unsigned long long>::max(),
|
||||
1ull,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
unsigned long fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<unsigned long>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0ul;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, unsigned long value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned long fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
unsigned long v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, unsigned long inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(ULongProperty, unsigned long, 0ul,
|
||||
numeric_limits<unsigned long>::lowest(),
|
||||
numeric_limits<unsigned long>::max(), 1ul,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned long, 0ul),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned long),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned long, 0ul),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned long),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
ULongProperty,
|
||||
unsigned long,
|
||||
0ul,
|
||||
std::numeric_limits<unsigned long>::lowest(),
|
||||
std::numeric_limits<unsigned long>::max(),
|
||||
1ul,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -29,54 +29,57 @@
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
unsigned short fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = (lua_isnumber(state, -1) == 1);
|
||||
if (success) {
|
||||
return static_cast<unsigned short>(lua_tonumber(state, -1));
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, unsigned short value) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned short fromStringConversion(std::string val, bool& success) {
|
||||
std::stringstream s(val);
|
||||
unsigned short v;
|
||||
s >> v;
|
||||
success = !s.fail();
|
||||
if (success) {
|
||||
return v;
|
||||
}
|
||||
else {
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val);
|
||||
}
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, unsigned short inValue) {
|
||||
outValue = std::to_string(inValue);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](lua_State* state, bool& success) -> TYPE { \
|
||||
success = (lua_isnumber(state, -1) == 1); \
|
||||
if (success) { \
|
||||
return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
} \
|
||||
else { \
|
||||
return DEFAULT_VALUE; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
[](lua_State* state, TYPE value) -> bool { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
[](std::string val, bool& success) -> TYPE { \
|
||||
std::stringstream s(val); \
|
||||
TYPE v; \
|
||||
s >> v; \
|
||||
success = !s.fail(); \
|
||||
if (success) { \
|
||||
return v; \
|
||||
} \
|
||||
else { \
|
||||
throw ghoul::RuntimeError("Conversion error for string: " + val); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(TYPE) \
|
||||
[](std::string& outValue, TYPE inValue) -> bool { \
|
||||
outValue = std::to_string(inValue); \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UShortProperty, unsigned short, 0,
|
||||
numeric_limits<unsigned short>::lowest(),
|
||||
numeric_limits<unsigned short>::max(), 1,
|
||||
DEFAULT_FROM_LUA_LAMBDA(unsigned short, 0),
|
||||
DEFAULT_TO_LUA_LAMBDA(unsigned short),
|
||||
DEFAULT_FROM_STRING_LAMBDA(unsigned short, 0),
|
||||
DEFAULT_TO_STRING_LAMBDA(unsigned short),
|
||||
LUA_TNUMBER)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
UShortProperty,
|
||||
unsigned short,
|
||||
0,
|
||||
std::numeric_limits<unsigned short>::lowest(),
|
||||
std::numeric_limits<unsigned short>::max(),
|
||||
1,
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TNUMBER
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -33,32 +33,32 @@ using std::numeric_limits;
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
// #define DEFAULT_FROM_LUA_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
// [](lua_State* state, bool& success) -> TYPE { \
|
||||
// success = (lua_isnumber(state, -1) == 1); \
|
||||
// if (success) { \
|
||||
// return static_cast<TYPE>(lua_tonumber(state, -1)); \
|
||||
// } \
|
||||
// else { \
|
||||
// return DEFAULT_VALUE; \
|
||||
// } \
|
||||
// #define DEFAULT_FROM_LUA_LAMBDA(wchar_t, DEFAULT_VALUE)
|
||||
// [](lua_State* state, bool& success) -> wchar_t {
|
||||
// success = (lua_isnumber(state, -1) == 1);
|
||||
// if (success) {
|
||||
// return static_cast<wchar_t>(lua_tonumber(state, -1));
|
||||
// }
|
||||
// else {
|
||||
// return DEFAULT_VALUE;
|
||||
// }
|
||||
// }
|
||||
|
||||
// #define DEFAULT_TO_LUA_LAMBDA(TYPE) \
|
||||
// [](lua_State* state, TYPE value) -> bool { \
|
||||
// lua_pushnumber(state, static_cast<lua_Number>(value)); \
|
||||
// return true; \
|
||||
// #define DEFAULT_TO_LUA_LAMBDA(wchar_t)
|
||||
// [](lua_State* state, wchar_t value) -> bool {
|
||||
// lua_pushnumber(state, static_cast<lua_Number>(value));
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// #define DEFAULT_FROM_STRING_LAMBDA(TYPE, DEFAULT_VALUE) \
|
||||
// [](std::string val, bool& success) -> TYPE { \
|
||||
// std::stringstream s(val); \
|
||||
// TYPE v; \
|
||||
// s >> v; \
|
||||
// success = !s.fail(); \
|
||||
// if (success) { \
|
||||
// return v; \
|
||||
// } \
|
||||
// #define DEFAULT_FROM_STRING_LAMBDA(wchar_t, DEFAULT_VALUE)
|
||||
// [](std::string val, bool& success) -> wchar_t {
|
||||
// std::stringstream s(val);
|
||||
// wchar_t v;
|
||||
// s >> v;
|
||||
// success = !s.fail();
|
||||
// if (success) {
|
||||
// return v;
|
||||
// }
|
||||
// }
|
||||
|
||||
//REGISTER_NUMERICALPROPERTY_SOURCE(WCharProperty, wchar_t, wchar_t(0),
|
||||
|
||||
@@ -26,41 +26,53 @@
|
||||
|
||||
#include <ghoul/lua/ghoul_lua.h>
|
||||
|
||||
namespace {
|
||||
|
||||
std::string fromLuaConversion(lua_State* state, bool& success) {
|
||||
success = lua_isstring(state, -1) == 1;
|
||||
if (success) {
|
||||
return lua_tostring(state, -1);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, std::string val) {
|
||||
lua_pushstring(state, val.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string fromStringConversion(std::string val, bool& success) {
|
||||
// An incoming string is of the form
|
||||
// "value"
|
||||
// so we want to remove the leading and trailing " characters
|
||||
if (val.size() > 2 && (val[0] == '"' && val[val.size() - 1] == '"')) {
|
||||
// Removing the first and last "
|
||||
success = true;
|
||||
return val.substr(1, val.size() - 2);
|
||||
}
|
||||
success = false;
|
||||
return val;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, std::string inValue) {
|
||||
outValue = "\"" + inValue + "\"";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(
|
||||
StringProperty,
|
||||
std::string,
|
||||
"",
|
||||
[](lua_State* state, bool& success) -> std::string {
|
||||
success = lua_isstring(state, -1) == 1;
|
||||
if (success) {
|
||||
return lua_tostring(state, -1);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
},
|
||||
[](lua_State* state, std::string val) -> bool {
|
||||
lua_pushstring(state, val.c_str());
|
||||
return true;
|
||||
},
|
||||
[](std::string val, bool& success) -> std::string {
|
||||
// An incoming string is of the form
|
||||
// "value"
|
||||
// so we want to remove the leading and trailing " characters
|
||||
if (val.size() > 2 && (val[0] == '"' && val[val.size() - 1] == '"')) {
|
||||
// Removing the first and last "
|
||||
success = true;
|
||||
return val.substr(1, val.size() - 2);
|
||||
}
|
||||
success = false;
|
||||
return val;
|
||||
},
|
||||
[](std::string& outValue, std::string inValue) -> bool {
|
||||
outValue = "\"" + inValue + "\"";
|
||||
return true;
|
||||
},
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TSTRING
|
||||
)
|
||||
|
||||
|
||||
@@ -30,86 +30,87 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::bvec2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::bvec2 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec2>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::bvec2(0);
|
||||
}
|
||||
if (lua_isboolean(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::bvec2(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::bvec2::value_type>(lua_toboolean(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::bvec2 val) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec2>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(val[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::bvec2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::bvec2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec2>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::bvec2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::bvec2 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec2>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ val) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(val[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec2Property, glm::bvec2, glm::bvec2(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec2, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(
|
||||
BVec2Property,
|
||||
glm::bvec2,
|
||||
glm::bvec2(false),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,86 +30,87 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::bvec3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::bvec3 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec3>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::bvec3(0);
|
||||
}
|
||||
if (lua_isboolean(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::bvec3(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::bvec3::value_type>(lua_toboolean(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::bvec3 val) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec3>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(val[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::bvec3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::bvec3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec3>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::bvec3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::bvec3 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec3>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ val) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(val[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec3Property, glm::bvec3, glm::bvec3(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec3, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(
|
||||
BVec3Property,
|
||||
glm::bvec3,
|
||||
glm::bvec3(false),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,86 +30,87 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::bvec4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::bvec4 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec4>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::bvec4(0);
|
||||
}
|
||||
if (lua_isboolean(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::bvec4(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::bvec4::value_type>(lua_toboolean(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::bvec4 val) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec4>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(val[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::bvec4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::bvec4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec4>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::bvec4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::bvec4 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::bvec4>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ val) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(val[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(BVec4Property, glm::bvec4, glm::bvec4(false),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::bvec4, lua_toboolean,
|
||||
lua_isboolean),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::bvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::bvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::bvec4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_TEMPLATEPROPERTY_SOURCE(
|
||||
BVec4Property,
|
||||
glm::bvec4,
|
||||
glm::bvec4(false),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dvec2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dvec2 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec2>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::dvec2(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dvec2(0);
|
||||
}
|
||||
else {
|
||||
result[i] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dvec2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec2>::value; ++i) {
|
||||
lua_pushnumber(state, value[i]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dvec2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dvec2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec2>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::dvec2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dvec2 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec2>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = __CONVFUNC__(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, value[i]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec2Property, glm::dvec2, glm::dvec2(0),
|
||||
glm::dvec2(numeric_limits<double>::lowest()),
|
||||
glm::dvec2(numeric_limits<double>::max()),
|
||||
glm::dvec2(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DVec2Property,
|
||||
glm::dvec2,
|
||||
glm::dvec2(0),
|
||||
glm::dvec2(std::numeric_limits<double>::lowest()),
|
||||
glm::dvec2(std::numeric_limits<double>::max()),
|
||||
glm::dvec2(0.01),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dvec3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dvec3 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec3>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::dvec3(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dvec3(0);
|
||||
}
|
||||
else {
|
||||
result[i] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dvec3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec3>::value; ++i) {
|
||||
lua_pushnumber(state, value[i]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dvec3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dvec3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec3>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::dvec3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dvec3 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec3>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = __CONVFUNC__(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, value[i]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec3Property, glm::dvec3, glm::dvec3(0),
|
||||
glm::dvec3(numeric_limits<double>::lowest()),
|
||||
glm::dvec3(numeric_limits<double>::max()),
|
||||
glm::dvec3(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DVec3Property,
|
||||
glm::dvec3,
|
||||
glm::dvec3(0),
|
||||
glm::dvec3(std::numeric_limits<double>::lowest()),
|
||||
glm::dvec3(std::numeric_limits<double>::max()),
|
||||
glm::dvec3(0.01),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::dvec4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::dvec4 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec4>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::dvec4(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::dvec4(0);
|
||||
}
|
||||
else {
|
||||
result[i] = lua_tonumber(state, -1);
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::dvec4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec4>::value; ++i) {
|
||||
lua_pushnumber(state, value[i]);
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::dvec4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::dvec4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec4>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::dvec4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::dvec4 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::dvec4>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = __CONVFUNC__(state, -1); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, value[i]); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(DVec4Property, glm::dvec4, glm::dvec4(0),
|
||||
glm::dvec4(numeric_limits<double>::lowest()),
|
||||
glm::dvec4(numeric_limits<double>::max()),
|
||||
glm::dvec4(0.01),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::dvec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::dvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::dvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::dvec4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
DVec4Property,
|
||||
glm::dvec4,
|
||||
glm::dvec4(0),
|
||||
glm::dvec4(std::numeric_limits<double>::lowest()),
|
||||
glm::dvec4(std::numeric_limits<double>::max()),
|
||||
glm::dvec4(0.01),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,87 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::ivec2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::ivec2 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec2>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::ivec2(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::ivec2(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::ivec2::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::ivec2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec2>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::ivec2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::ivec2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec2>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::ivec2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::ivec2 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec2>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State* state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State* state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec2Property, glm::ivec2, glm::ivec2(0),
|
||||
glm::ivec2(numeric_limits<int>::lowest()),
|
||||
glm::ivec2(numeric_limits<int>::max()), glm::ivec2(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
IVec2Property,
|
||||
glm::ivec2,
|
||||
glm::ivec2(0),
|
||||
glm::ivec2(std::numeric_limits<int>::lowest()),
|
||||
glm::ivec2(std::numeric_limits<int>::max()),
|
||||
glm::ivec2(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,87 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::ivec3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::ivec3 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec3>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::ivec3(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::ivec3(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::ivec3::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::ivec3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec3>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::ivec3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::ivec3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec3>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::ivec3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::ivec3 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec3>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec3Property, glm::ivec3, glm::ivec3(0),
|
||||
glm::ivec3(numeric_limits<int>::lowest()),
|
||||
glm::ivec3(numeric_limits<int>::max()), glm::ivec3(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
IVec3Property,
|
||||
glm::ivec3,
|
||||
glm::ivec3(0),
|
||||
glm::ivec3(std::numeric_limits<int>::lowest()),
|
||||
glm::ivec3(std::numeric_limits<int>::max()),
|
||||
glm::ivec3(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,87 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::ivec4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::ivec4 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec4>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::ivec4(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::ivec4(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::ivec4::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::ivec4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec4>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::ivec4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::ivec4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec4>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::ivec4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::ivec4 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::ivec4>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(IVec4Property, glm::ivec4, glm::ivec4(0),
|
||||
glm::ivec4(numeric_limits<int>::lowest()),
|
||||
glm::ivec4(numeric_limits<int>::max()), glm::ivec4(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::ivec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::ivec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::ivec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::ivec4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
IVec4Property,
|
||||
glm::ivec4,
|
||||
glm::ivec4(0),
|
||||
glm::ivec4(std::numeric_limits<int>::lowest()),
|
||||
glm::ivec4(std::numeric_limits<int>::max()),
|
||||
glm::ivec4(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::uvec2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::uvec2 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec2>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::uvec2(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::uvec2(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::uvec2::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::uvec2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec2>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::uvec2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::uvec2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec2>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::uvec2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::uvec2 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec2>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec2Property, glm::uvec2, glm::uvec2(0),
|
||||
glm::uvec2(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec2(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec2(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
UVec2Property,
|
||||
glm::uvec2,
|
||||
glm::uvec2(0),
|
||||
glm::uvec2(std::numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec2(std::numeric_limits<unsigned int>::max()),
|
||||
glm::uvec2(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::uvec3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::uvec3 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec3>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::uvec3(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::uvec3(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::uvec3::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::uvec3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec3>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::uvec3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::uvec3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec3>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::uvec3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::uvec3 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec3>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec3Property, glm::uvec3, glm::uvec3(0),
|
||||
glm::uvec3(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec3(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec3(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
UVec3Property,
|
||||
glm::uvec3,
|
||||
glm::uvec3(0),
|
||||
glm::uvec3(std::numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec3(std::numeric_limits<unsigned int>::max()),
|
||||
glm::uvec3(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::uvec4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::uvec4 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec4>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::uvec4(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::uvec4(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::uvec4::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::uvec4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec4>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::uvec4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::uvec4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec4>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::uvec4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::uvec4 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::uvec4>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(UVec4Property, glm::uvec4, glm::uvec4(0),
|
||||
glm::uvec4(numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec4(numeric_limits<unsigned int>::max()),
|
||||
glm::uvec4(1),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::uvec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::uvec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::uvec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::uvec4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
UVec4Property,
|
||||
glm::uvec4,
|
||||
glm::uvec4(0),
|
||||
glm::uvec4(std::numeric_limits<unsigned int>::lowest()),
|
||||
glm::uvec4(std::numeric_limits<unsigned int>::max()),
|
||||
glm::uvec4(1),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::vec2 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::vec2 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec2>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::vec2(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::vec2(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::vec2::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::vec2 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec2>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec2 fromStringConversion(std::string val, bool& success) {
|
||||
glm::vec2 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec2>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::vec2::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::vec2 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec2>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec2Property, glm::vec2, glm::vec2(0),
|
||||
glm::vec2(numeric_limits<float>::lowest()),
|
||||
glm::vec2(numeric_limits<float>::max()),
|
||||
glm::vec2(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec2, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec2),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec2),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec2),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Vec2Property,
|
||||
glm::vec2,
|
||||
glm::vec2(0),
|
||||
glm::vec2(std::numeric_limits<float>::lowest()),
|
||||
glm::vec2(std::numeric_limits<float>::max()),
|
||||
glm::vec2(0.01f),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::vec3 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::vec3 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec3>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::vec3(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::vec3(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::vec3::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::vec3 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec3>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec3 fromStringConversion(std::string val, bool& success) {
|
||||
glm::vec3 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec3>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::vec3::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::vec3 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec3>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec3Property, glm::vec3, glm::vec3(0),
|
||||
glm::vec3(numeric_limits<float>::lowest()),
|
||||
glm::vec3(numeric_limits<float>::max()),
|
||||
glm::vec3(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec3, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec3),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec3),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec3),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Vec3Property,
|
||||
glm::vec3,
|
||||
glm::vec3(0),
|
||||
glm::vec3(std::numeric_limits<float>::lowest()),
|
||||
glm::vec3(std::numeric_limits<float>::max()),
|
||||
glm::vec3(0.01f),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
@@ -30,88 +30,90 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
using std::numeric_limits;
|
||||
namespace {
|
||||
|
||||
glm::vec4 fromLuaConversion(lua_State* state, bool& success) {
|
||||
glm::vec4 result;
|
||||
lua_pushnil(state);
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec4>::value; ++i) {
|
||||
int hasNext = lua_next(state, -2);
|
||||
if (hasNext != 1) {
|
||||
success = false;
|
||||
return glm::vec4(0);
|
||||
}
|
||||
if (lua_isnumber(state, -1) != 1) {
|
||||
success = false;
|
||||
return glm::vec4(0);
|
||||
}
|
||||
else {
|
||||
result[i] = static_cast<glm::vec4::value_type>(lua_tonumber(state, -1));
|
||||
lua_pop(state, 1);
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toLuaConversion(lua_State* state, glm::vec4 value) {
|
||||
lua_newtable(state);
|
||||
int number = 1;
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec4>::value; ++i) {
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i]));
|
||||
lua_setfield(state, -2, std::to_string(number).c_str());
|
||||
++number;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
glm::vec4 fromStringConversion(std::string val, bool& success) {
|
||||
glm::vec4 result;
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ',');
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec4>::value; ++i) {
|
||||
std::stringstream s(tokens[i]);
|
||||
glm::vec4::value_type v;
|
||||
s >> v;
|
||||
if (s.fail()) {
|
||||
success = false;
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
result[i] = v;
|
||||
}
|
||||
}
|
||||
success = true;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool toStringConversion(std::string& outValue, glm::vec4 inValue) {
|
||||
outValue = "{";
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<glm::vec4>::value; ++i) {
|
||||
outValue += std::to_string(inValue[i]) + ",";
|
||||
}
|
||||
outValue.pop_back();
|
||||
outValue += "}";
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace openspace::properties {
|
||||
|
||||
#define DEFAULT_FROM_LUA_LAMBDA(__TYPE__, __CONVFUNC__, __TESTFUNC__) \
|
||||
[](lua_State * state, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
lua_pushnil(state); \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
int hasNext = lua_next(state, -2); \
|
||||
if (hasNext != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} \
|
||||
if (__TESTFUNC__(state, -1) != 1) { \
|
||||
success = false; \
|
||||
return __TYPE__(0); \
|
||||
} else { \
|
||||
result[i] = static_cast<__TYPE__::value_type>(__CONVFUNC__(state, -1)); \
|
||||
lua_pop(state, 1); \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_LUA_LAMBDA(__TYPE__) \
|
||||
[](lua_State * state, __TYPE__ value) -> bool { \
|
||||
lua_newtable(state); \
|
||||
int number = 1; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
lua_pushnumber(state, static_cast<lua_Number>(value[i])); \
|
||||
lua_setfield(state, -2, std::to_string(number).c_str()); \
|
||||
++number; \
|
||||
} \
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define DEFAULT_FROM_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string val, bool& success) -> __TYPE__ { \
|
||||
__TYPE__ result; \
|
||||
std::vector<std::string> tokens = ghoul::tokenizeString(val, ','); \
|
||||
if (tokens.size() != static_cast<size_t>(result.length())) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
std::stringstream s(tokens[i]); \
|
||||
__TYPE__::value_type v; \
|
||||
s >> v; \
|
||||
if (s.fail()) { \
|
||||
success = false; \
|
||||
return result; \
|
||||
} \
|
||||
else { \
|
||||
result[i] = v; \
|
||||
} \
|
||||
} \
|
||||
success = true; \
|
||||
return result; \
|
||||
}
|
||||
|
||||
#define DEFAULT_TO_STRING_LAMBDA(__TYPE__) \
|
||||
[](std::string& outValue, __TYPE__ inValue) -> bool { \
|
||||
outValue = "{"; \
|
||||
for (glm::length_t i = 0; i < ghoul::glm_components<__TYPE__>::value; ++i) { \
|
||||
outValue += std::to_string(inValue[i]) + ","; \
|
||||
} \
|
||||
outValue.pop_back(); \
|
||||
outValue += "}"; \
|
||||
return true; \
|
||||
}
|
||||
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(Vec4Property, glm::vec4, glm::vec4(0),
|
||||
glm::vec4(numeric_limits<float>::lowest()),
|
||||
glm::vec4(numeric_limits<float>::max()),
|
||||
glm::vec4(0.01f),
|
||||
DEFAULT_FROM_LUA_LAMBDA(glm::vec4, lua_tonumber,
|
||||
lua_isnumber),
|
||||
DEFAULT_TO_LUA_LAMBDA(glm::vec4),
|
||||
DEFAULT_FROM_STRING_LAMBDA(glm::vec4),
|
||||
DEFAULT_TO_STRING_LAMBDA(glm::vec4),
|
||||
LUA_TTABLE)
|
||||
REGISTER_NUMERICALPROPERTY_SOURCE(
|
||||
Vec4Property,
|
||||
glm::vec4,
|
||||
glm::vec4(0),
|
||||
glm::vec4(std::numeric_limits<float>::lowest()),
|
||||
glm::vec4(std::numeric_limits<float>::max()),
|
||||
glm::vec4(0.01f),
|
||||
fromLuaConversion,
|
||||
toLuaConversion,
|
||||
fromStringConversion,
|
||||
toStringConversion,
|
||||
LUA_TTABLE
|
||||
)
|
||||
|
||||
} // namespace openspace::properties
|
||||
|
||||
Reference in New Issue
Block a user