xoreos  0.0.5
util.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/aurora/lua/util.h"
26 #include "src/aurora/lua/stack.h"
28 #include "src/aurora/lua/table.h"
29 
30 namespace Aurora {
31 
32 namespace Lua {
33 
34 void *getRawCppObjectFromStack(const Stack &stack, int index) {
35  switch (stack.getTypeAt(index)) {
37  TableRef instance = stack.getTableAt(index);
38  instance.setMetaAccessEnabled(false);
39  if (instance.isUserTypeAt("CPP_instance")) {
40  return instance.getRawUserTypeAt("CPP_instance");
41  }
42  }
45  return stack.getRawUserTypeAt(index);
46  default:
47  break;
48  }
49  return 0;
50 }
51 
53  switch (var.getType()) {
55  TableRef instance = var.getTable();
56  instance.setMetaAccessEnabled(false);
57  if (instance.isUserTypeAt("CPP_instance")) {
58  return instance.getRawUserTypeAt("CPP_instance");
59  }
60  }
63  return var.getRawUserType();
64  default:
65  break;
66  }
67  return 0;
68 }
69 
70 } // End of namespace Lua
71 
72 } // End of namespace Aurora
void * getRawUserType() const
Definition: variable.cpp:351
void * getRawCppObjectFromVariable(const Variable &var)
Definition: util.cpp:52
TableRef getTableAt(int index) const
Return a table at the given index in the stack.
Definition: stack.cpp:162
TableRef & getTable()
Definition: variable.cpp:327
Type getType() const
Definition: variable.cpp:279
bool isUserTypeAt(int index, const Common::UString &type="") const
Check whether the value at the given index is a usertype value.
Definition: table.cpp:500
void * getRawUserTypeAt(int index, const Common::UString &type="") const
Return a raw usertype value at the given index in the stack.
Definition: stack.cpp:176
Type getTypeAt(int index) const
Definition: stack.cpp:218
A Lua stack wrapper.
Definition: stack.h:41
#define XOREOS_FALLTHROUGH
Definition: fallthrough.h:60
void * getRawCppObjectFromStack(const Stack &stack, int index)
Definition: util.cpp:34
void * getRawUserTypeAt(int index, const Common::UString &type="") const
Return a usertype value at the given index in the stack.
Definition: table.cpp:344
A reference to a Lua table.
Definition: table.h:37
A reference to a Lua table.
Lua helpers.
Lua variable.
A Lua stack wrapper.
void setMetaAccessEnabled(bool enabled)
Enable/Disable access to the table elements using metamethods.
Definition: table.cpp:126