Permalink
Browse files

Add getters to LuaTable

  • Loading branch information...
1 parent 317c822 commit a096f3db9c7f0264de414bd9f881177c34319af6 @laarmen committed Apr 19, 2012
Showing with 39 additions and 0 deletions.
  1. +39 −0 src/LuaTable.h
View
39 src/LuaTable.h
@@ -5,6 +5,8 @@
#include <set>
#include <string>
+#include "PiObject.h"
+
extern "C" {
#include "lua/lua.h"
#include "lua/lauxlib.h"
@@ -29,6 +31,43 @@ class LuaTable {
// Returns the Lua context to ease chaining the commands.
lua_State * PushToStack(const std::string & key);
+ template <class T> inline T * Get(const std::string & key) {
+ lua_State * l = PushToStack(key);
+ T* ret = LuaObject<T>::GetFromLua(-1);
+ lua_pop(l, 1);
+ return ret;
+ }
+ std::string GetString(const std::string & key) {
+ lua_State * l = PushToStack(key);
+ T* ret = LuaObject<T>::GetFromLua(-1);
+ lua_pop(l, 1);
+ return ret;
+ }
+ bool GetBool(const std::string & key) {
+ lua_State * l = PushToStack(key);
+ double ret = lua_toboolean(l, -1);
+ lua_pop(l, 1);
+ return ret;
+ }
+ int GetInt(const std::string & key) {
+ lua_State * l = PushToStack(key);
+ int ret = lua_tointeger(l, -1);
+ lua_pop(l, 1);
+ return ret;
+ }
+ bool GetDouble(const std::string & key) {
+ lua_State * l = PushToStack(key);
+ double ret = lua_tonumber(l, -1);
+ lua_pop(l, 1);
+ return ret;
+ }
+ LuaTable GetTable(const std::string & key) {
+ lua_State * l = PushToStack(key);
+ LuaTable ret(-1);
+ lua_pop(l, 1);
+ return ret;
+ }
+
private:
static void UpdateLoaded(int removed_index);

0 comments on commit a096f3d

Please sign in to comment.