mirror of
https://github.com/glest/glest-source.git
synced 2025-08-24 00:42:50 +02:00
- added a few new lua methods to register cell 'areas' for unit or for factions for wciwow
This commit is contained in:
@@ -14,16 +14,17 @@
|
||||
|
||||
#include <string>
|
||||
#include <lua.hpp>
|
||||
#include <vec.h>
|
||||
#include "vec.h"
|
||||
#include "xml_parser.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using std::string;
|
||||
|
||||
using Shared::Graphics::Vec2i;
|
||||
using Shared::Graphics::Vec4i;
|
||||
using Shared::Xml::XmlNode;
|
||||
|
||||
namespace Shared{ namespace Lua{
|
||||
namespace Shared { namespace Lua {
|
||||
|
||||
typedef lua_State LuaHandle;
|
||||
typedef int(*LuaFunction)(LuaHandle*);
|
||||
@@ -32,7 +33,7 @@ typedef int(*LuaFunction)(LuaHandle*);
|
||||
// class LuaScript
|
||||
// =====================================================
|
||||
|
||||
class LuaScript{
|
||||
class LuaScript {
|
||||
private:
|
||||
LuaHandle *luaState;
|
||||
int argumentCount;
|
||||
@@ -63,7 +64,7 @@ private:
|
||||
// class LuaArguments
|
||||
// =====================================================
|
||||
|
||||
class LuaArguments{
|
||||
class LuaArguments {
|
||||
private:
|
||||
lua_State *luaState;
|
||||
int returnCount;
|
||||
@@ -75,11 +76,13 @@ public:
|
||||
string getString(int argumentIndex) const;
|
||||
void * getGenericData(int argumentIndex) const;
|
||||
Vec2i getVec2i(int argumentIndex) const;
|
||||
Vec4i getVec4i(int argumentIndex) const;
|
||||
int getReturnCount() const {return returnCount;}
|
||||
|
||||
void returnInt(int value);
|
||||
void returnString(const string &value);
|
||||
void returnVec2i(const Vec2i &value);
|
||||
void returnVec4i(const Vec4i &value);
|
||||
void returnVectorInt(const vector<int> &value);
|
||||
|
||||
private:
|
||||
|
@@ -20,7 +20,7 @@
|
||||
using namespace std;
|
||||
using namespace Shared::Util;
|
||||
|
||||
namespace Shared{ namespace Lua{
|
||||
namespace Shared { namespace Lua {
|
||||
|
||||
//
|
||||
// This class wraps streflop for LuaScript. We need to toggle the data type
|
||||
@@ -590,6 +590,42 @@ Vec2i LuaArguments::getVec2i(int argumentIndex) const{
|
||||
return v;
|
||||
}
|
||||
|
||||
Vec4i LuaArguments::getVec4i(int argumentIndex) const {
|
||||
Lua_STREFLOP_Wrapper streflopWrapper;
|
||||
|
||||
Vec4i v;
|
||||
|
||||
if(!lua_istable(luaState, argumentIndex)){
|
||||
throwLuaError("Can not get vec4i from Lua state, value on the stack is not a table");
|
||||
}
|
||||
|
||||
#if LUA_VERSION_NUM > 501
|
||||
if(lua_rawlen(luaState, argumentIndex) != 4 ) {
|
||||
#else
|
||||
if(luaL_getn(luaState, argumentIndex) != 4) {
|
||||
#endif
|
||||
throwLuaError("Can not get vec4i from Lua state, array size not 4");
|
||||
}
|
||||
|
||||
lua_rawgeti(luaState, argumentIndex, 1);
|
||||
v.x= luaL_checkint(luaState, argumentIndex);
|
||||
lua_pop(luaState, 1);
|
||||
|
||||
lua_rawgeti(luaState, argumentIndex, 2);
|
||||
v.y= luaL_checkint(luaState, argumentIndex);
|
||||
lua_pop(luaState, 1);
|
||||
|
||||
lua_rawgeti(luaState, argumentIndex, 3);
|
||||
v.z= luaL_checkint(luaState, argumentIndex);
|
||||
lua_pop(luaState, 1);
|
||||
|
||||
lua_rawgeti(luaState, argumentIndex, 4);
|
||||
v.w= luaL_checkint(luaState, argumentIndex);
|
||||
lua_pop(luaState, 1);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void LuaArguments::returnInt(int value){
|
||||
Lua_STREFLOP_Wrapper streflopWrapper;
|
||||
|
||||
@@ -618,6 +654,27 @@ void LuaArguments::returnVec2i(const Vec2i &value){
|
||||
lua_rawseti(luaState, -2, 2);
|
||||
}
|
||||
|
||||
void LuaArguments::returnVec4i(const Vec4i &value) {
|
||||
//Lua_STREFLOP_Wrapper streflopWrapper;
|
||||
|
||||
++returnCount;
|
||||
|
||||
lua_newtable(luaState);
|
||||
|
||||
lua_pushnumber(luaState, value.x);
|
||||
lua_rawseti(luaState, -2, 1);
|
||||
|
||||
lua_pushnumber(luaState, value.y);
|
||||
lua_rawseti(luaState, -2, 2);
|
||||
|
||||
lua_pushnumber(luaState, value.z);
|
||||
lua_rawseti(luaState, -2, 3);
|
||||
|
||||
lua_pushnumber(luaState, value.w);
|
||||
lua_rawseti(luaState, -2, 4);
|
||||
|
||||
}
|
||||
|
||||
void LuaArguments::returnVectorInt(const vector<int> &value) {
|
||||
//Lua_STREFLOP_Wrapper streflopWrapper;
|
||||
|
||||
|
Reference in New Issue
Block a user