]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/Script.hh
ray-scene intersection
[chaz/yoink] / src / Moof / Script.hh
index 2f285cecc2bcdd740529783fcc8d4f7ea0fa581b..f67c62c20d27f67a09732650d4cdb4adb70b88c4 100644 (file)
@@ -125,7 +125,7 @@ public:
                 */
                Value(lua_State* s = 0, int i = 0) :
                        index(i),
-                       state(s) {}
+                       mState(s) {}
 
                /**
                 * A copied value presently points to the same value, except the real
@@ -136,22 +136,22 @@ public:
 
                Value(const Value& copy) :
                        index(copy.getRealIndex()),
-                       state(copy.state) {}
+                       mState(copy.mState) {}
 
 
                // check the type of the value
-               bool isBoolean() const   { return (bool)lua_isboolean(state, index); }
-               bool isFunction() const  { return (bool)lua_isfunction(state, index); }
-               bool isNil() const       { return (bool)lua_isnil(state, index); }
-               bool isNone() const      { return (bool)lua_isnone(state, index); }
-               bool isValid() const     { return state != 0 && !isNone(); }
-               bool isNoneOrNil() const { return (bool)lua_isnoneornil(state, index); }
-               bool isNumber() const    { return (bool)lua_isnumber(state, index); }
-               bool isString() const    { return (bool)lua_isstring(state, index); }
-               bool isTable() const     { return (bool)lua_istable(state, index); }
-               bool isThread() const    { return (bool)lua_isthread(state, index); }
-               bool isData() const      { return (bool)lua_isuserdata(state, index); }
-               bool isLightData() const { return (bool)lua_islightuserdata(state, index); }
+               bool isBoolean() const   { return (bool)lua_isboolean(mState, index); }
+               bool isFunction() const  { return (bool)lua_isfunction(mState, index); }
+               bool isNil() const       { return (bool)lua_isnil(mState, index); }
+               bool isNone() const      { return (bool)lua_isnone(mState, index); }
+               bool isValid() const     { return mState != 0 && !isNone(); }
+               bool isNoneOrNil() const { return (bool)lua_isnoneornil(mState, index); }
+               bool isNumber() const    { return (bool)lua_isnumber(mState, index); }
+               bool isString() const    { return (bool)lua_isstring(mState, index); }
+               bool isTable() const     { return (bool)lua_istable(mState, index); }
+               bool isThread() const    { return (bool)lua_isthread(mState, index); }
+               bool isData() const      { return (bool)lua_isuserdata(mState, index); }
+               bool isLightData() const { return (bool)lua_islightuserdata(mState, index); }
 
                /**
                 * Check the value and throw an error if its the wrong type.  There's a
@@ -170,54 +170,54 @@ public:
                {
                        if (type != getType())
                        {
-                               luaL_typerror(state, index, lua_typename(state, type));
+                               luaL_typerror(mState, index, lua_typename(mState, type));
                        }
                }
 
                void throwError(const char* error)
                {
-                       luaL_argerror(state, index, error);
+                       luaL_argerror(mState, index, error);
                }
 
 
                Value& requireBoolean()
                {
-                       if (!isBoolean()) luaL_typerror(state, index, "boolean");
+                       if (!isBoolean()) luaL_typerror(mState, index, "boolean");
                        return *this;
                }
                Value& requireNumber()
                {
-                       if (!isNumber()) luaL_typerror(state, index, "number");
+                       if (!isNumber()) luaL_typerror(mState, index, "number");
                        return *this;
                }
                Value& requireString()
                {
-                       if (!isString()) luaL_typerror(state, index, "string");
+                       if (!isString()) luaL_typerror(mState, index, "string");
                        return *this;
                }
                Value& requireTable()
                {
-                       if (!isTable()) luaL_typerror(state, index, "table");
+                       if (!isTable()) luaL_typerror(mState, index, "table");
                        return *this;
                }
                Value& requireFunction()
                {
-                       if (!isFunction()) luaL_typerror(state, index, "function");
+                       if (!isFunction()) luaL_typerror(mState, index, "function");
                        return *this;
                }
                Value& requireData()
                {
-                       if (!isData()) luaL_typerror(state, index, "data");
+                       if (!isData()) luaL_typerror(mState, index, "data");
                        return *this;
                }
                Value& requireNil()
                {
-                       if (!isNil()) luaL_typerror(state, index, "nil");
+                       if (!isNil()) luaL_typerror(mState, index, "nil");
                        return *this;
                }
                Value& requireThread()
                {
-                       if (!isThread()) luaL_typerror(state, index, "thread");
+                       if (!isThread()) luaL_typerror(mState, index, "thread");
                        return *this;
                }
 
@@ -228,7 +228,7 @@ public:
 
                Type getType() const
                {
-                       return (Type)lua_type(state, index);
+                       return (Type)lua_type(mState, index);
                }
 
                /**
@@ -237,7 +237,7 @@ public:
 
                std::string getTypeName() const
                {
-                       return std::string(luaL_typename(state, index));
+                       return std::string(luaL_typename(mState, index));
                }
 
 
@@ -247,12 +247,12 @@ public:
 
                size_t getLength() const
                {
-                       return lua_objlen(state, index);
+                       return lua_objlen(mState, index);
                }
 
                int getRealIndex() const
                {
-                       if (index < 0) return lua_gettop(state) + 1 + index;
+                       if (index < 0) return lua_gettop(mState) + 1 + index;
                        else           return index;
                }
 
@@ -263,13 +263,13 @@ public:
 
                const void* getIdentifier() const
                {
-                       return lua_topointer(state, index);
+                       return lua_topointer(mState, index);
                }
 
 
                bool operator == (const Value& rhs) const
                {
-                       return (bool)lua_equal(state, index, rhs.index);
+                       return (bool)lua_equal(mState, index, rhs.index);
                }
                bool operator != (const Value& rhs) const
                {
@@ -277,7 +277,7 @@ public:
                }
                bool operator < (const Value& rhs) const
                {
-                       return (bool)lua_lessthan(state, index, rhs.index);
+                       return (bool)lua_lessthan(mState, index, rhs.index);
                }
                bool operator <= (const Value& rhs) const
                {
@@ -293,7 +293,7 @@ public:
                }
                operator bool () const
                {
-                       return (bool)lua_toboolean(state, index);
+                       return (bool)lua_toboolean(mState, index);
                }
 
                Value& operator = (const Value& rhs)
@@ -313,7 +313,7 @@ public:
                {
                        if (isNumber())
                        {
-                               value = (T)lua_tointeger(state, index);
+                               value = (T)lua_tointeger(mState, index);
                                return true;
                        }
                        return false;
@@ -323,7 +323,7 @@ public:
                {
                        if (isNumber())
                        {
-                               value = (float)lua_tonumber(state, index);
+                               value = (float)lua_tonumber(mState, index);
                                return true;
                        }
                        return false;
@@ -332,7 +332,7 @@ public:
                {
                        if (isNumber())
                        {
-                               value = (double)lua_tonumber(state, index);
+                               value = (double)lua_tonumber(mState, index);
                                return true;
                        }
                        return false;
@@ -342,7 +342,7 @@ public:
                {
                        if (isBoolean())
                        {
-                               value = (bool)lua_toboolean(state, index);
+                               value = (bool)lua_toboolean(mState, index);
                                return true;
                        }
                        return false;
@@ -353,7 +353,7 @@ public:
                        if (isString())
                        {
                                size_t size;
-                               const char* str = lua_tolstring(state, index, &size);
+                               const char* str = lua_tolstring(mState, index, &size);
                                value.assign(str, size);
                                return true;
                        }
@@ -367,19 +367,19 @@ public:
 
                        array.clear();
 
-                       Value   value(state, -1);
+                       Value   value(mState, -1);
                        int             realIndex = getRealIndex();
 
                        bool done = false;
                        for (int i = 1; !done; ++i)
                        {
-                               lua_rawgeti(state, realIndex, i);
+                               lua_rawgeti(mState, realIndex, i);
 
                                T v;
                                if (value.get(v)) array.push_back(v);
                                else              done = true;
 
-                               lua_pop(state, 1);
+                               lua_pop(mState, 1);
                        }
 
                        return true;
@@ -392,12 +392,12 @@ public:
 
                        dictionary.clear();
 
-                       Value   key(state, -2);
-                       Value   value(state, -1);
+                       Value   key(mState, -2);
+                       Value   value(mState, -1);
                        int             realIndex = getRealIndex();
 
-                       lua_pushnil(state);
-                       while (lua_next(state, realIndex) != 0)
+                       lua_pushnil(mState);
+                       while (lua_next(mState, realIndex) != 0)
                        {
                                std::string k;
                                if (!key.isNumber() && key.get(k))
@@ -405,9 +405,9 @@ public:
                                        T v;
                                        if (value.get(v)) dictionary[k] = v;
                                }
-                               lua_pop(state, 1);
+                               lua_pop(mState, 1);
                        }
-                       lua_pop(state, 1);
+                       lua_pop(mState, 1);
 
                        return true;
                }
@@ -420,7 +420,7 @@ public:
 
                void pushCopy() const
                {
-                       lua_pushvalue(state, index);
+                       lua_pushvalue(mState, index);
                }
 
                /**
@@ -429,12 +429,12 @@ public:
 
                void replaceWithTop()
                {
-                       lua_replace(state, index);
+                       lua_replace(mState, index);
                }
 
                void remove()
                {
-                       lua_remove(state, index);
+                       lua_remove(mState, index);
                }
 
                /**
@@ -444,29 +444,35 @@ public:
 
                void insertTopHere()
                {
-                       lua_insert(state, index);
+                       lua_insert(mState, index);
                }
 
                
                void pushMetatable() const
                {
-                       lua_getmetatable(state, index);
+                       lua_getmetatable(mState, index);
                }
 
                void pushField() const
                {
-                       lua_gettable(state, index);
+                       lua_gettable(mState, index);
                }
 
                void pushField(const std::string& name) const
                {
-                       lua_getfield(state, index, name.c_str());
+                       lua_getfield(mState, index, name.c_str());
+               }
+
+               void pushField(size_t index) const
+               {
+                       lua_pushinteger(mState, lua_Integer(index));
+                       pushField();
                }
 
 
        private:
 
-               lua_State* state;
+               lua_State* mState;
        };
 
 
This page took 0.029277 seconds and 4 git commands to generate.