Otclient  14/8/2020
luavaluecasts.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2020 OTClient <https://github.com/edubart/otclient>
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20  * THE SOFTWARE.
21  */
22 
23 #include "luavaluecasts.h"
25 
26 int push_luavalue(const Outfit& outfit)
27 {
28  g_lua.createTable(0, 8);
29  g_lua.pushInteger(outfit.getId());
30  g_lua.setField("type");
31  g_lua.pushInteger(outfit.getAuxId());
32  g_lua.setField("auxType");
34  g_lua.pushInteger(outfit.getAddons());
35  g_lua.setField("addons");
36  }
37  g_lua.pushInteger(outfit.getHead());
38  g_lua.setField("head");
39  g_lua.pushInteger(outfit.getBody());
40  g_lua.setField("body");
41  g_lua.pushInteger(outfit.getLegs());
42  g_lua.setField("legs");
43  g_lua.pushInteger(outfit.getFeet());
44  g_lua.setField("feet");
46  g_lua.pushInteger(outfit.getMount());
47  g_lua.setField("mount");
48  }
49  return 1;
50 }
51 
52 bool luavalue_cast(int index, Outfit& outfit)
53 {
54  if(g_lua.isTable(index)) {
55  g_lua.getField("type", index);
56  outfit.setId(g_lua.popInteger());
57  g_lua.getField("auxType", index);
58  outfit.setAuxId(g_lua.popInteger());
60  g_lua.getField("addons", index);
61  outfit.setAddons(g_lua.popInteger());
62  }
63  g_lua.getField("head", index);
64  outfit.setHead(g_lua.popInteger());
65  g_lua.getField("body", index);
66  outfit.setBody(g_lua.popInteger());
67  g_lua.getField("legs", index);
68  outfit.setLegs(g_lua.popInteger());
69  g_lua.getField("feet", index);
70  outfit.setFeet(g_lua.popInteger());
72  g_lua.getField("mount", index);
73  outfit.setMount(g_lua.popInteger());
74  }
75  return true;
76  }
77  return false;
78 }
79 
80 int push_luavalue(const Position& pos)
81 {
82  if(pos.isValid()) {
83  g_lua.createTable(0, 3);
84  g_lua.pushInteger(pos.x);
85  g_lua.setField("x");
86  g_lua.pushInteger(pos.y);
87  g_lua.setField("y");
88  g_lua.pushInteger(pos.z);
89  g_lua.setField("z");
90  } else
91  g_lua.pushNil();
92  return 1;
93 }
94 
95 bool luavalue_cast(int index, Position& pos)
96 {
97  if(g_lua.isTable(index)) {
98  g_lua.getField("x", index);
99  pos.x = g_lua.popInteger();
100  g_lua.getField("y", index);
101  pos.y = g_lua.popInteger();
102  g_lua.getField("z", index);
103  pos.z = g_lua.popInteger();
104  return true;
105  }
106  return false;
107 }
108 
109 int push_luavalue(const MarketData& data)
110 {
111  g_lua.createTable(0, 6);
112  g_lua.pushInteger(data.category);
113  g_lua.setField("category");
114  g_lua.pushString(data.name);
115  g_lua.setField("name");
117  g_lua.setField("requiredLevel");
119  g_lua.setField("restrictVocation");
120  g_lua.pushInteger(data.showAs);
121  g_lua.setField("showAs");
122  g_lua.pushInteger(data.tradeAs);
123  g_lua.setField("tradeAs");
124  return 1;
125 }
126 
127 bool luavalue_cast(int index, MarketData& data)
128 {
129  if(g_lua.isTable(index)) {
130  g_lua.getField("category", index);
131  data.category = g_lua.popInteger();
132  g_lua.getField("name", index);
133  data.name = g_lua.popString();
134  g_lua.getField("requiredLevel", index);
135  data.requiredLevel = g_lua.popInteger();
136  g_lua.getField("restrictVocation", index);
138  g_lua.getField("showAs", index);
139  data.showAs = g_lua.popInteger();
140  g_lua.getField("tradeAs", index);
141  data.tradeAs = g_lua.popInteger();
142  return true;
143  }
144  return false;
145 }
146 
147 int push_luavalue(const Light& light)
148 {
149  g_lua.createTable(0, 2);
150  g_lua.pushInteger(light.color);
151  g_lua.setField("color");
152  g_lua.pushInteger(light.intensity);
153  g_lua.setField("intensity");
154  return 1;
155 }
156 
157 bool luavalue_cast(int index, Light& light)
158 {
159  if(g_lua.isTable(index)) {
160  g_lua.getField("color", index);
161  light.color = g_lua.popInteger();
162  g_lua.getField("intensity", index);
163  light.intensity = g_lua.popInteger();
164  return true;
165  }
166  return false;
167 }
168 
169 int push_luavalue(const UnjustifiedPoints& unjustifiedPoints)
170 {
171  g_lua.createTable(0, 7);
172  g_lua.pushInteger(unjustifiedPoints.killsDay);
173  g_lua.setField("killsDay");
174  g_lua.pushInteger(unjustifiedPoints.killsDayRemaining);
175  g_lua.setField("killsDayRemaining");
176  g_lua.pushInteger(unjustifiedPoints.killsWeek);
177  g_lua.setField("killsWeek");
178  g_lua.pushInteger(unjustifiedPoints.killsWeekRemaining);
179  g_lua.setField("killsWeekRemaining");
180  g_lua.pushInteger(unjustifiedPoints.killsMonth);
181  g_lua.setField("killsMonth");
182  g_lua.pushInteger(unjustifiedPoints.killsMonthRemaining);
183  g_lua.setField("killsMonthRemaining");
184  g_lua.pushInteger(unjustifiedPoints.skullTime);
185  g_lua.setField("skullTime");
186  return 1;
187 }
188 
189 bool luavalue_cast(int index, UnjustifiedPoints& unjustifiedPoints)
190 {
191  if(g_lua.isTable(index)) {
192  g_lua.getField("killsDay", index);
193  unjustifiedPoints.killsDay = g_lua.popInteger();
194  g_lua.getField("killsDayRemaining", index);
195  unjustifiedPoints.killsDayRemaining = g_lua.popInteger();
196  g_lua.getField("killsWeek", index);
197  unjustifiedPoints.killsWeek = g_lua.popInteger();
198  g_lua.getField("killsWeekRemaining", index);
199  unjustifiedPoints.killsWeekRemaining = g_lua.popInteger();
200  g_lua.getField("killsMonth", index);
201  unjustifiedPoints.killsMonth = g_lua.popInteger();
202  g_lua.getField("killsMonthRemaining", index);
203  unjustifiedPoints.killsMonthRemaining = g_lua.popInteger();
204  g_lua.getField("skullTime", index);
205  unjustifiedPoints.skullTime = g_lua.popInteger();
206  return true;
207  }
208  return false;
209 }
Outfit::getMount
int getMount() const
Definition: outfit.h:60
push_luavalue
int push_luavalue(const Outfit &outfit)
Definition: luavaluecasts.cpp:26
MarketData::requiredLevel
uint16 requiredLevel
Definition: thingtype.h:111
Outfit::setBody
void setBody(int body)
Definition: outfit.h:44
Outfit::getBody
int getBody() const
Definition: outfit.h:56
Outfit::setFeet
void setFeet(int feet)
Definition: outfit.h:46
Outfit::getId
int getId() const
Definition: outfit.h:53
Outfit::setAddons
void setAddons(int addons)
Definition: outfit.h:47
UnjustifiedPoints::killsDayRemaining
uint8 killsDayRemaining
Definition: game.h:50
UnjustifiedPoints::killsDay
uint8 killsDay
Definition: game.h:49
Position::x
int x
Definition: position.h:243
Otc::GamePlayerAddons
@ GamePlayerAddons
Definition: const.h:387
Position::isValid
bool isValid() const
Definition: position.h:182
luavaluecasts.h
luavalue_cast
bool luavalue_cast(int index, Outfit &outfit)
Definition: luavaluecasts.cpp:52
UnjustifiedPoints::killsWeek
uint8 killsWeek
Definition: game.h:51
luainterface.h
MarketData::category
int category
Definition: thingtype.h:110
Outfit::getFeet
int getFeet() const
Definition: outfit.h:58
g_game
Game g_game
Definition: game.cpp:37
Position::y
int y
Definition: position.h:244
Otc::GamePlayerMounts
@ GamePlayerMounts
Definition: const.h:357
Outfit::getAddons
int getAddons() const
Definition: outfit.h:59
Outfit::setAuxId
void setAuxId(int id)
Definition: outfit.h:42
Position::z
short z
Definition: position.h:245
LuaInterface::getField
void getField(const char *key, int index=-1)
Definition: luainterface.cpp:880
UnjustifiedPoints::skullTime
uint8 skullTime
Definition: game.h:55
Light::intensity
uint8 intensity
Definition: thingtype.h:119
LuaInterface::createTable
void createTable(int narr, int nrec)
Definition: luainterface.cpp:989
LuaInterface::popString
std::string popString()
Definition: luainterface.cpp:1031
Outfit
Definition: outfit.h:29
LuaInterface::popInteger
long popInteger()
Definition: luainterface.cpp:1007
g_lua
LuaInterface g_lua
Definition: luainterface.cpp:31
Outfit::getLegs
int getLegs() const
Definition: outfit.h:57
Outfit::setId
void setId(int id)
Definition: outfit.h:41
Position
Definition: position.h:33
Outfit::setHead
void setHead(int head)
Definition: outfit.h:43
UnjustifiedPoints::killsMonthRemaining
uint8 killsMonthRemaining
Definition: game.h:54
MarketData::tradeAs
uint16 tradeAs
Definition: thingtype.h:114
Outfit::setMount
void setMount(int mount)
Definition: outfit.h:48
UnjustifiedPoints::killsWeekRemaining
uint8 killsWeekRemaining
Definition: game.h:52
Game::getFeature
bool getFeature(Otc::GameFeature feature)
Definition: game.h:310
LuaInterface::pushString
void pushString(const std::string &v)
Definition: luainterface.cpp:1091
MarketData::showAs
uint16 showAs
Definition: thingtype.h:113
LuaInterface::isTable
bool isTable(int index=-1)
Definition: luainterface.cpp:1174
Outfit::getAuxId
int getAuxId() const
Definition: outfit.h:54
LuaInterface::setField
void setField(const char *key, int index=-2)
Definition: luainterface.cpp:887
Light::color
uint8 color
Definition: thingtype.h:120
MarketData
Definition: thingtype.h:108
Light
Definition: thingtype.h:117
UnjustifiedPoints::killsMonth
uint8 killsMonth
Definition: game.h:53
Outfit::getHead
int getHead() const
Definition: outfit.h:55
MarketData::name
std::string name
Definition: thingtype.h:109
LuaInterface::pushInteger
void pushInteger(long v)
Definition: luainterface.cpp:1066
MarketData::restrictVocation
uint16 restrictVocation
Definition: thingtype.h:112
LuaInterface::pushNil
void pushNil()
Definition: luainterface.cpp:1060
UnjustifiedPoints
Definition: game.h:39
Outfit::setLegs
void setLegs(int legs)
Definition: outfit.h:45