From 41a06b69f979e57ca583339819b01dc4b53e2869 Mon Sep 17 00:00:00 2001 From: Josh Simmons Date: Sun, 16 Dec 2012 18:56:52 +1100 Subject: [PATCH 1/3] Get rid of some dos line endings and unify indentation. Honestly I have some serious fucking ocd issues. --- luacpp.hpp | 30 +-- luacpp/error.hpp | 38 ++-- luacpp/function.hpp | 114 ++++++------ luacpp/nil.hpp | 26 +-- luacpp/object.hpp | 38 ++-- luacpp/reference.hpp | 48 ++--- luacpp/stack.hpp | 212 ++++++++++----------- luacpp/state.hpp | 272 +++++++++++++-------------- luacpp/table.hpp | 376 +++++++++++++++++++------------------- luacpp/tuplecall.hpp | 30 +-- luacpp/types.hpp | 126 ++++++------- readme.markdown | 76 ++++---- src/error.cpp | 6 +- src/object.cpp | 30 +-- src/reference.cpp | 102 +++++------ src/stack.cpp | 186 +++++++++---------- src/state.cpp | 114 ++++++------ src/table.cpp | 8 +- test/error.cpp | 26 +-- test/exceptionhandler.cpp | 52 +++--- test/functions.cpp | 22 +-- test/multiple_returns.cpp | 12 +- test/nil.cpp | 12 +- 23 files changed, 982 insertions(+), 974 deletions(-) diff --git a/luacpp.hpp b/luacpp.hpp index 2bef65a..73633b1 100644 --- a/luacpp.hpp +++ b/luacpp.hpp @@ -3,34 +3,34 @@ // doxygen index /** - @mainpage - @section hello_sec Hello, world! - @code + @mainpage + @section hello_sec Hello, world! + @code #include int main() { - lua::state lua; - lua.openLibs(); + lua::state lua; + lua.openLibs(); - lua::function print = lua["print"]; - print("Hello, world!"); + lua::function print = lua["print"]; + print("Hello, world!"); } - @endcode + @endcode - @section intro_sec Introduction + @section intro_sec Introduction - LuaC++ is a bridge between Lua and C++ which aims to remove the need to use the C API, - including the Lua stack. It currently supports Lua version 5.1. + LuaC++ is a bridge between Lua and C++ which aims to remove the need to use the C API, + including the Lua stack. It currently supports Lua version 5.1. - @section download_sec Download - Full source code can be found at http://github.com/JakobOvrum/LuaCpp + @section download_sec Download + Full source code can be found at http://github.com/JakobOvrum/LuaCpp */ //doxygen examples /** - @example hello.cpp - @example config.cpp + @example hello.cpp + @example config.cpp */ #include "luacpp/error.hpp" diff --git a/luacpp/error.hpp b/luacpp/error.hpp index 84755e0..acfdd00 100644 --- a/luacpp/error.hpp +++ b/luacpp/error.hpp @@ -5,25 +5,25 @@ namespace lua { - ///Lua error exception - /** - Thrown when an unhandled Lua error is raised. - Keep in mind that the actual C++ exception is only thrown if Lua - doesn't know what to do with one of its errors (Lua panic). This - means that all cases of lua::error being thrown (as referenced in documentation) - can, and will, be caught by protected Lua calls before being propagated as - this exception. - */ - class error : public std::runtime_error - { - public: - ///Basic constructor - /** - @param what error message - \internal - */ - error(const char* what); - }; + ///Lua error exception + /** + Thrown when an unhandled Lua error is raised. + Keep in mind that the actual C++ exception is only thrown if Lua + doesn't know what to do with one of its errors (Lua panic). This + means that all cases of lua::error being thrown (as referenced in documentation) + can, and will, be caught by protected Lua calls before being propagated as + this exception. + */ + class error : public std::runtime_error + { + public: + ///Basic constructor + /** + @param what error message + \internal + */ + error(const char* what); + }; } #endif diff --git a/luacpp/function.hpp b/luacpp/function.hpp index d3b3e9d..b3a29fe 100644 --- a/luacpp/function.hpp +++ b/luacpp/function.hpp @@ -9,71 +9,71 @@ namespace lua { - ///Lua function - /** - Object representing a Lua function. - */ - class function : virtual public reference - { - public: - ///Create empty reference to function - /** \internal */ - function() : reference(){} + ///Lua function + /** + Object representing a Lua function. + */ + class function : virtual public reference + { + public: + ///Create empty reference to function + /** \internal */ + function() : reference(){} - ///Create reference to function on stack - /** - @param L stack containing function - @param index position on stack - \internal - */ - function(lua_State* L, int index = -1) : reference(L, index) - { - assertType(L, index, type::function); - } + ///Create reference to function on stack + /** + @param L stack containing function + @param index position on stack + \internal + */ + function(lua_State* L, int index = -1) : reference(L, index) + { + assertType(L, index, type::function); + } - ///Call this function - /** - @param args arguments to pass to function - */ - template - void operator()(Args&&... args) - { - push(); - pushArg(state(), args...); - lua_call(state(), sizeof...(args), 0); - } + ///Call this function + /** + @param args arguments to pass to function + */ + template + void operator()(Args&&... args) + { + push(); + pushArg(state(), args...); + lua_call(state(), sizeof...(args), 0); + } - ///Call this function and get return value(s) - /** - @tparam Rets types of expected return values, in order + ///Call this function and get return value(s) + /** + @tparam Rets types of expected return values, in order - @param args arguments to pass to function - @return tuple of return values - */ - // with return values - template - std::tuple call(Args&&... args) - { - push(); - pushArg(state(), args...); - lua_call(state(), sizeof...(args), sizeof...(Rets)); + @param args arguments to pass to function + @return tuple of return values + */ + // with return values + template + std::tuple call(Args&&... args) + { + push(); + pushArg(state(), args...); + lua_call(state(), sizeof...(args), sizeof...(Rets)); - std::tuple ret; - luaToTuple::fill(state(), ret); + std::tuple ret; + luaToTuple::fill(state(), ret); - return ret; - } + return ret; + } - private: - template - void pushArg(lua_State* L, T&& arg, Args&&... args) - { - pushValue(L, arg); - pushArg(L, args...); - } + private: + template + void pushArg(lua_State* L, T&& arg, Args&&... args) + { + pushValue(L, arg); + pushArg(L, args...); + } - void pushArg(lua_State* L){} - }; + void pushArg(lua_State* L){} + }; } #endif diff --git a/luacpp/nil.hpp b/luacpp/nil.hpp index 029d50c..f6dd04c 100644 --- a/luacpp/nil.hpp +++ b/luacpp/nil.hpp @@ -3,20 +3,20 @@ namespace lua { - ///Unique type representing Lua nil - /** - Use the constant lua::nil. - */ - struct nil_t - { - }; + ///Unique type representing Lua nil + /** + Use the constant lua::nil. + */ + struct nil_t + { + }; - ///Object instance representing Lua nil - /** - Useful for clearing keys in tables. - @see table::index - */ - extern nil_t nil; + ///Object instance representing Lua nil + /** + Useful for clearing keys in tables. + @see table::index + */ + extern nil_t nil; } #endif diff --git a/luacpp/object.hpp b/luacpp/object.hpp index b462499..c03967c 100644 --- a/luacpp/object.hpp +++ b/luacpp/object.hpp @@ -8,31 +8,31 @@ namespace lua { - class object : virtual public reference, public table, public function - { - public: - object(lua_State* L, int index) : reference(L, index) - { - } + class object : virtual public reference, public table, public function + { + public: + object(lua_State* L, int index) : reference(L, index) + { + } - object(){} + object(){} - template - operator T() - { - push(); - assertType(state(), -1, typeOf(state())); + template + operator T() + { + push(); + assertType(state(), -1, typeOf(state())); - T t; + T t; - getValue(state(), -1, t); + getValue(state(), -1, t); - return t; - } + return t; + } - bool operator==(const reference& r); - bool operator==(const nil_t& t); - }; + bool operator==(const reference& r); + bool operator==(const nil_t& t); + }; } #endif diff --git a/luacpp/reference.hpp b/luacpp/reference.hpp index 0cc777e..bf10dc8 100644 --- a/luacpp/reference.hpp +++ b/luacpp/reference.hpp @@ -8,37 +8,37 @@ struct lua_State; namespace lua { - class object; + class object; - class reference - { - public: - reference(lua_State* L, int index = -1); - reference(const reference& c); - virtual ~reference(); + class reference + { + public: + reference(lua_State* L, int index = -1); + reference(const reference& c); + virtual ~reference(); - type::luatype type() const; - const char* typeName() const; + type::luatype type() const; + const char* typeName() const; - protected: - reference(); - const reference& operator=(const reference& c); + protected: + reference(); + const reference& operator=(const reference& c); - void push() const; - inline lua_State* state() const - { - return L; - } + void push() const; + inline lua_State* state() const + { + return L; + } - private: - int copyRef() const; + private: + int copyRef() const; - lua_State* L; - int ref; + lua_State* L; + int ref; - friend void pushValue(lua_State* L, reference& ref); - friend class object; - }; + friend void pushValue(lua_State* L, reference& ref); + friend class object; + }; } #endif diff --git a/luacpp/stack.hpp b/luacpp/stack.hpp index f2d0e0e..eb0e204 100644 --- a/luacpp/stack.hpp +++ b/luacpp/stack.hpp @@ -12,112 +12,112 @@ namespace lua { - class table; - class function; - class object; - class nil_t; - - // from Lua - void getValue(lua_State* L, int index, table& r); - void getValue(lua_State* L, int index, function& r); - void getValue(lua_State* L, int index, object& r); - void getValue(lua_State* L, int index, lua_Integer& r); - void getValue(lua_State* L, int index, lua_Number& r); - void getValue(lua_State* L, int index, bool& r); - void getValue(lua_State* L, int index, const char*& r); - void getValue(lua_State* L, int index, const char*& r, size_t& len); - void getValue(lua_State* L, int index, std::string& r); - - template - inline void getArg(lua_State* L, int narg, T& r) - { - int type = typeOf(L); - int t = lua_type(L, narg); - if(t != type) - luaL_typerror(L, narg, lua_typename(L, type)); - - getValue(L, narg, r); - } - - inline void getArg(lua_State* L, int narg, object& r) - { - getValue(L, narg, r); - } - - // to Lua - class reference; - - void pushValue(lua_State* L, reference& ref); - void pushValue(lua_State* L, lua_Integer i); - void pushValue(lua_State* L, lua_Number n); - void pushValue(lua_State* L, bool b); - void pushValue(lua_State* L, const char* s); - void pushValue(lua_State* L, const char* s, size_t len); - void pushValue(lua_State* L, const std::string& str); - void pushValue(lua_State* L, lua_CFunction f); - void pushValue(lua_State* L, nil_t& n); - - template - struct luaToTuple - { - static void fill(lua_State* L, std::tuple& args) - { - getArg(L, sizeof...(Args) - n + 1, std::get(args)); - luaToTuple::fill(L, args); - } - }; - - template - struct luaToTuple<0, Args...> - { - static void fill(lua_State* L, std::tuple& args) {} - }; - - // regular single return value - template - struct tupleCaller - { - static int call(lua_State* L, R (*f)(Args...), std::tuple& args) - { - R r = tuplecall::call(f, args); - pushValue(L, r); - return 1; - } - }; - - // no return value - template - struct tupleCaller - { - static int call(lua_State* L, void (*f)(Args...), std::tuple& args) - { - tuplecall::call(f, args); - return 0; - } - }; - - template - int functionWrapper(lua_State* L) - { - size_t top = lua_gettop(L); - if(top < sizeof...(Args)) - luaL_error(L, "expected %d arguments, got %d", sizeof...(Args), top); - - typedef R (*T)(Args...); - T f = (T)(lua_touserdata(L, lua_upvalueindex(1))); - - std::tuple args; - luaToTuple::fill(L, args); - - return tupleCaller::call(L, f, args); - } - - template - void pushValue(lua_State* L, R (*f)(Args...)) - { - lua_pushlightuserdata(L, (void*)f); - lua_pushcclosure(L, functionWrapper, 1); - } + class table; + class function; + class object; + class nil_t; + + // from Lua + void getValue(lua_State* L, int index, table& r); + void getValue(lua_State* L, int index, function& r); + void getValue(lua_State* L, int index, object& r); + void getValue(lua_State* L, int index, lua_Integer& r); + void getValue(lua_State* L, int index, lua_Number& r); + void getValue(lua_State* L, int index, bool& r); + void getValue(lua_State* L, int index, const char*& r); + void getValue(lua_State* L, int index, const char*& r, size_t& len); + void getValue(lua_State* L, int index, std::string& r); + + template + inline void getArg(lua_State* L, int narg, T& r) + { + int type = typeOf(L); + int t = lua_type(L, narg); + if(t != type) + luaL_typerror(L, narg, lua_typename(L, type)); + + getValue(L, narg, r); + } + + inline void getArg(lua_State* L, int narg, object& r) + { + getValue(L, narg, r); + } + + // to Lua + class reference; + + void pushValue(lua_State* L, reference& ref); + void pushValue(lua_State* L, lua_Integer i); + void pushValue(lua_State* L, lua_Number n); + void pushValue(lua_State* L, bool b); + void pushValue(lua_State* L, const char* s); + void pushValue(lua_State* L, const char* s, size_t len); + void pushValue(lua_State* L, const std::string& str); + void pushValue(lua_State* L, lua_CFunction f); + void pushValue(lua_State* L, nil_t& n); + + template + struct luaToTuple + { + static void fill(lua_State* L, std::tuple& args) + { + getArg(L, sizeof...(Args) - n + 1, std::get(args)); + luaToTuple::fill(L, args); + } + }; + + template + struct luaToTuple<0, Args...> + { + static void fill(lua_State* L, std::tuple& args) {} + }; + + // regular single return value + template + struct tupleCaller + { + static int call(lua_State* L, R (*f)(Args...), std::tuple& args) + { + R r = tuplecall::call(f, args); + pushValue(L, r); + return 1; + } + }; + + // no return value + template + struct tupleCaller + { + static int call(lua_State* L, void (*f)(Args...), std::tuple& args) + { + tuplecall::call(f, args); + return 0; + } + }; + + template + int functionWrapper(lua_State* L) + { + size_t top = lua_gettop(L); + if(top < sizeof...(Args)) + luaL_error(L, "expected %d arguments, got %d", sizeof...(Args), top); + + typedef R (*T)(Args...); + T f = (T)(lua_touserdata(L, lua_upvalueindex(1))); + + std::tuple args; + luaToTuple::fill(L, args); + + return tupleCaller::call(L, f, args); + } + + template + void pushValue(lua_State* L, R (*f)(Args...)) + { + lua_pushlightuserdata(L, (void*)f); + lua_pushcclosure(L, functionWrapper, 1); + } } #endif diff --git a/luacpp/state.hpp b/luacpp/state.hpp index 3531f73..293f607 100644 --- a/luacpp/state.hpp +++ b/luacpp/state.hpp @@ -7,142 +7,142 @@ struct lua_State; namespace lua { - ///Lua state - /** - Object representing an instance of Lua. - */ - class state - { - public: - ///Create a new Lua state - /** - Keep in mind that this does not import the in-built libraries. - @see openLibs() - */ - state(); - - ///Create a new wrapper for an existing state - /** - Wraps an existing lua_State. The underlying state will not be closed when this object is destroyed. - This constructor is useful if your lua_State is not managed by your code. - @param L lua_State object to wrap - */ - state(lua_State* L); - - ///Import in-built libraries - /** - The in-built Lua standard library is not available until this function is called. - */ - void openLibs(); - - ///Run a string of Lua - /** - @param code Lua code to execute - @throw lua::error thrown for syntax errors and uncaught runtime errors - */ - void doString(const char* code); - - ///Run a Lua script - /** - @param path Path to script file to execute - @throw lua::error thrown for syntax errors and uncaught runtime errors - */ - void doFile(const char* path); - - ///Get global table - /** - @return Reference to the global environment - */ - table& globals(); - - ///Get registry table - /** - Note: do not put integer keys in this table, as they're reserved by the Lua reference mechanism which is used in LuaC++. - @return Reference to the registry - */ - table& registry(); - - ///Get global table - /** - @return Immutable reference to the global environment - */ - const table& globals() const; - - ///Get registry table - /** - @return Immutable reference to the registry - */ - const table& registry() const; - - ///Create a new, empty table - /** - @param narr pre-allocate space for this number of array elements - @param nrec pre-allocate space for this number of non-array elements - @return empty table - */ - table newTable(int narr = 0, int nrec = 0); - - ///Get global variable - /** - @tparam T variable type - - @param key variable key - @return variable value - See table::index for a list of possible types for T and U. - - @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) - */ - template - T get(U key) const - { - return _G.get(key); - } - - ///Set global variable - /** - @param key variable key - @param value variable value - See table::index for a list of possible types for T and U. - - @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) - */ - template - void set(T key, U value) - { - _G.set(key, value); - } - - ///Use bracket syntax to get or set global variables - /** - @param key variable key - @return assignable and convertible type - @see table::index - */ - template - table::index operator[](T&& key) const - { - return _G[key]; - } - - private: - void init(); - - // lua_State* resource handle, to cleanly make it destruct last - class handle - { - private: - lua_State* L; - bool owner; - - public: - handle(lua_State* L, bool owner) : L(L), owner(owner) {} - ~handle(){ if(owner) lua_close(L); } - - inline operator lua_State*(){ return L; } - }; - table _G, _R; - handle L; - }; + ///Lua state + /** + Object representing an instance of Lua. + */ + class state + { + public: + ///Create a new Lua state + /** + Keep in mind that this does not import the in-built libraries. + @see openLibs() + */ + state(); + + ///Create a new wrapper for an existing state + /** + Wraps an existing lua_State. The underlying state will not be closed when this object is destroyed. + This constructor is useful if your lua_State is not managed by your code. + @param L lua_State object to wrap + */ + state(lua_State* L); + + ///Import in-built libraries + /** + The in-built Lua standard library is not available until this function is called. + */ + void openLibs(); + + ///Run a string of Lua + /** + @param code Lua code to execute + @throw lua::error thrown for syntax errors and uncaught runtime errors + */ + void doString(const char* code); + + ///Run a Lua script + /** + @param path Path to script file to execute + @throw lua::error thrown for syntax errors and uncaught runtime errors + */ + void doFile(const char* path); + + ///Get global table + /** + @return Reference to the global environment + */ + table& globals(); + + ///Get registry table + /** + Note: do not put integer keys in this table, as they're reserved by the Lua reference mechanism which is used in LuaC++. + @return Reference to the registry + */ + table& registry(); + + ///Get global table + /** + @return Immutable reference to the global environment + */ + const table& globals() const; + + ///Get registry table + /** + @return Immutable reference to the registry + */ + const table& registry() const; + + ///Create a new, empty table + /** + @param narr pre-allocate space for this number of array elements + @param nrec pre-allocate space for this number of non-array elements + @return empty table + */ + table newTable(int narr = 0, int nrec = 0); + + ///Get global variable + /** + @tparam T variable type + + @param key variable key + @return variable value + See table::index for a list of possible types for T and U. + + @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) + */ + template + T get(U key) const + { + return _G.get(key); + } + + ///Set global variable + /** + @param key variable key + @param value variable value + See table::index for a list of possible types for T and U. + + @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) + */ + template + void set(T key, U value) + { + _G.set(key, value); + } + + ///Use bracket syntax to get or set global variables + /** + @param key variable key + @return assignable and convertible type + @see table::index + */ + template + table::index operator[](T&& key) const + { + return _G[key]; + } + + private: + void init(); + + // lua_State* resource handle, to cleanly make it destruct last + class handle + { + private: + lua_State* L; + bool owner; + + public: + handle(lua_State* L, bool owner) : L(L), owner(owner) {} + ~handle(){ if(owner) lua_close(L); } + + inline operator lua_State*(){ return L; } + }; + table _G, _R; + handle L; + }; } #endif diff --git a/luacpp/table.hpp b/luacpp/table.hpp index d95a952..1c4f4f7 100644 --- a/luacpp/table.hpp +++ b/luacpp/table.hpp @@ -8,194 +8,194 @@ namespace lua { - template - inline void checkType(lua_State* L, int index) - { - assertType(L, -1, typeOf(L)); - } - - template<> - inline void checkType(lua_State* L, int index) {} - - ///Lua table - /** - Object representing a Lua table. - */ - class table : virtual public reference - { - public: - ///Create empty reference to table - /** @internal */ - table() : reference(){} - - ///Create reference to table on stack - /** - @param L stack containing table - @param index position on stack - @internal - */ - table(lua_State* L, int index = -1); - - ///Set this table's metatable - /** - @param meta new metatable - */ - void setMetaTable(const table& meta); - - ///Get this table's metatable - /** - @return this table's metatable - @throw lua::error thrown if this table's metatable is nil - */ - table getMetaTable(); - - ///Check for metatable - /** - @return boolean whether or not this table has a metatable - */ - bool hasMetaTable(); - - ///Look up variable in table - /** - @tparam T variable type - - @param key variable key - @return variable value - - @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) - */ - template - T get(U key) const - { - push(); - pushValue(state(), key); - lua_gettable(state(), -2); - - checkType(state(), -1); - - T t; - getValue(state(), -1, t); - - lua_pop(state(), 2); - return t; - } - - ///Set variable in table - /** - @param key variable key - @param value variable value - - @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) - */ - template - void set(T key, U value) - { - push(); - pushValue(state(), key); - pushValue(state(), value); - lua_settable(state(), -3); - lua_pop(state(), 1); - } - - ///Assignable and convertible result of bracket-style lookup - /** - @tparam T type of key - - Returned by operator[] for lua::table and lua::state. - Types supported for T and U: - - number - - lua_Integer (default 'int') - - lua_Number (default 'double') - - - string - - const char* - - std::string - - - boolean - - bool - - - table - - lua::table - - - function - - lua::function - - any function R (*)(args...) where R is any - convertible type, and args is a list of parameters - of any convertible type. This is not supported whenever - the type is returned to C++, only when pushing to Lua. - - - nil - - lua::nil_t (use lua::nil) - - Note: this object is only assignable when non-const. - */ - template - class index - { - public: - ///Create new index association - /** - @param t table to operate on - @param k key in table to operate on - @internal - */ - index(table& t, T& k) : tab(t), key(k){} - - ///Set t[k] - /** - @param value new value for t[k] - - @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) - */ - template - index& operator=(U value) - { - tab.set(key, value); - return *this; - } - - ///Get t[k] - /** - @tparam U type to convert to - - @return value of t[k] as type U - @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) - */ - template - operator U() const - { - return tab.get(key); - } - - private: - table& tab; - T& key; - }; - - ///Get or set variable in table with bracket-style syntax - /** - @param key variable key - @return assignable and convertible handle for specified key in this table - @see table::index - */ - template - index operator[](T&& key) - { - return index(*this, key); - } - - ///Get variable in table with bracket-style syntax - /** - @param key variable key - @return convertible handle for specified key in this table - @see table::index - */ - template - const index operator[](T&& key) const - { - return index(const_cast(*this), key); - } - }; + template + inline void checkType(lua_State* L, int index) + { + assertType(L, -1, typeOf(L)); + } + + template<> + inline void checkType(lua_State* L, int index) {} + + ///Lua table + /** + Object representing a Lua table. + */ + class table : virtual public reference + { + public: + ///Create empty reference to table + /** @internal */ + table() : reference(){} + + ///Create reference to table on stack + /** + @param L stack containing table + @param index position on stack + @internal + */ + table(lua_State* L, int index = -1); + + ///Set this table's metatable + /** + @param meta new metatable + */ + void setMetaTable(const table& meta); + + ///Get this table's metatable + /** + @return this table's metatable + @throw lua::error thrown if this table's metatable is nil + */ + table getMetaTable(); + + ///Check for metatable + /** + @return boolean whether or not this table has a metatable + */ + bool hasMetaTable(); + + ///Look up variable in table + /** + @tparam T variable type + + @param key variable key + @return variable value + + @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) + */ + template + T get(U key) const + { + push(); + pushValue(state(), key); + lua_gettable(state(), -2); + + checkType(state(), -1); + + T t; + getValue(state(), -1, t); + + lua_pop(state(), 2); + return t; + } + + ///Set variable in table + /** + @param key variable key + @param value variable value + + @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) + */ + template + void set(T key, U value) + { + push(); + pushValue(state(), key); + pushValue(state(), value); + lua_settable(state(), -3); + lua_pop(state(), 1); + } + + ///Assignable and convertible result of bracket-style lookup + /** + @tparam T type of key + + Returned by operator[] for lua::table and lua::state. + Types supported for T and U: + - number + - lua_Integer (default 'int') + - lua_Number (default 'double') + + - string + - const char* + - std::string + + - boolean + - bool + + - table + - lua::table + + - function + - lua::function + - any function R (*)(args...) where R is any + convertible type, and args is a list of parameters + of any convertible type. This is not supported whenever + the type is returned to C++, only when pushing to Lua. + + - nil + - lua::nil_t (use lua::nil) + + Note: this object is only assignable when non-const. + */ + template + class index + { + public: + ///Create new index association + /** + @param t table to operate on + @param k key in table to operate on + @internal + */ + index(table& t, T& k) : tab(t), key(k){} + + ///Set t[k] + /** + @param value new value for t[k] + + @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) + */ + template + index& operator=(U value) + { + tab.set(key, value); + return *this; + } + + ///Get t[k] + /** + @tparam U type to convert to + + @return value of t[k] as type U + @throw lua::error thrown if T or U are not convertible to Lua types (see table::index) + */ + template + operator U() const + { + return tab.get(key); + } + + private: + table& tab; + T& key; + }; + + ///Get or set variable in table with bracket-style syntax + /** + @param key variable key + @return assignable and convertible handle for specified key in this table + @see table::index + */ + template + index operator[](T&& key) + { + return index(*this, key); + } + + ///Get variable in table with bracket-style syntax + /** + @param key variable key + @return convertible handle for specified key in this table + @see table::index + */ + template + const index operator[](T&& key) const + { + return index(const_cast(*this), key); + } + }; } #endif diff --git a/luacpp/tuplecall.hpp b/luacpp/tuplecall.hpp index 2b740f0..6791e43 100644 --- a/luacpp/tuplecall.hpp +++ b/luacpp/tuplecall.hpp @@ -7,23 +7,23 @@ namespace tuplecall { - template - struct dispatcher : public dispatcher {}; + template + struct dispatcher : public dispatcher {}; - template - struct dispatcher - { - static Return call(Func func, const Tuple& args) - { - return func(std::get (args)...); - } - }; + template + struct dispatcher + { + static Return call(Func func, const Tuple& args) + { + return func(std::get (args)...); + } + }; - template - Return call(Return (* func) (Args...), const std::tuple & args) - { - return dispatcher , sizeof...(Args)>::call(func, args); - } + template + Return call(Return (* func) (Args...), const std::tuple & args) + { + return dispatcher , sizeof...(Args)>::call(func, args); + } } #endif diff --git a/luacpp/types.hpp b/luacpp/types.hpp index 4cabce0..d08c627 100644 --- a/luacpp/types.hpp +++ b/luacpp/types.hpp @@ -8,79 +8,79 @@ namespace lua { - namespace type - { - enum luatype - { - none = LUA_TNONE, - string = LUA_TSTRING, - number = LUA_TNUMBER, - thread = LUA_TTHREAD, - boolean = LUA_TBOOLEAN, - function = LUA_TFUNCTION, - userdata = LUA_TUSERDATA, - lightuserdata = LUA_TLIGHTUSERDATA, - table = LUA_TTABLE - }; - } + namespace type + { + enum luatype + { + none = LUA_TNONE, + string = LUA_TSTRING, + number = LUA_TNUMBER, + thread = LUA_TTHREAD, + boolean = LUA_TBOOLEAN, + function = LUA_TFUNCTION, + userdata = LUA_TUSERDATA, + lightuserdata = LUA_TLIGHTUSERDATA, + table = LUA_TTABLE + }; + } - inline void assertType(lua_State* L, int index, type::luatype expectedType) - { - int t = lua_type(L, index); - if(t != expectedType) - luaL_error(L, "expected %s, got %s", lua_typename(L, expectedType), lua_typename(L, t)); - } + inline void assertType(lua_State* L, int index, type::luatype expectedType) + { + int t = lua_type(L, index); + if(t != expectedType) + luaL_error(L, "expected %s, got %s", lua_typename(L, expectedType), lua_typename(L, t)); + } - class table; - class function; + class table; + class function; - template - inline type::luatype typeOf(lua_State* L) - { - return type::none; - } + template + inline type::luatype typeOf(lua_State* L) + { + return type::none; + } - template<> - inline type::luatype typeOf(lua_State* L) - { - return type::table; - } + template<> + inline type::luatype typeOf
(lua_State* L) + { + return type::table; + } - template<> - inline type::luatype typeOf(lua_State* L) - { - return type::function; - } + template<> + inline type::luatype typeOf(lua_State* L) + { + return type::function; + } - template<> - inline type::luatype typeOf(lua_State* L) - { - return type::number; - } + template<> + inline type::luatype typeOf(lua_State* L) + { + return type::number; + } - template<> - inline type::luatype typeOf(lua_State* L) - { - return type::number; - } + template<> + inline type::luatype typeOf(lua_State* L) + { + return type::number; + } - template<> - inline type::luatype typeOf(lua_State* L) - { - return type::boolean; - } + template<> + inline type::luatype typeOf(lua_State* L) + { + return type::boolean; + } - template<> - inline type::luatype typeOf(lua_State* L) - { - return type::string; - } + template<> + inline type::luatype typeOf(lua_State* L) + { + return type::string; + } - template<> - inline type::luatype typeOf(lua_State* L) - { - return type::string; - } + template<> + inline type::luatype typeOf(lua_State* L) + { + return type::string; + } } #endif diff --git a/readme.markdown b/readme.markdown index 7be3cb7..79c4ca6 100644 --- a/readme.markdown +++ b/readme.markdown @@ -1,37 +1,45 @@ -Hello, world! -============================== - #include - - int main() - { - lua::state lua; - lua.openLibs(); - - lua::function print = lua["print"]; - print("Hello, world!"); - } - -LuaC++ -============================== -LuaC++ is a bridge between Lua and C++ which aims to remove the need to use the C API, including the Lua stack. It currently supports Lua version 5.1. - Check out the example/ and test/ subdirectories for usage examples. +Hello, world! +============================== + #include + + int main() + { + lua::state lua; + lua.openLibs(); + + lua::function print = lua["print"]; + print("Hello, world!"); + } + +LuaC++ +============================== +LuaC++ is a bridge between Lua and C++ which aims to remove the need to use the +C API, including the Lua stack. It currently supports Lua version 5.1. Check +out the example/ and test/ subdirectories for usage examples. Documentation ------------------------------ -Documentation can be browsed online [here](http://jakobovrum.github.com/LuaCpp/index.html), or checked out at the gh-pages branch. - -Alternatively, run `doxygen Doxyfile` from the project root directory to generate documentation from source (you might want to change the OUTPUT_DIRECTORY configuration value found in Doxyfile). - -Requirements ------------------------------- -LuaC++ makes use of the following C++0x features, which means your favorite compiler might not yet be able to compile and use LuaC++: - - * variadic templates - * rvalue references - * the tuple module - -Additionally, as LuaC++ uses C++ exceptions for error handling, make sure your Lua library is compiled as C++. - -License -============================== -LuaC++ is licensed under the terms of the MIT license, see the LICENSE file for more information. +Documentation can be browsed online +[here](http://jakobovrum.github.com/LuaCpp/index.html), or checked out at the +gh-pages branch. + +Alternatively, run `doxygen Doxyfile` from the project root directory to +generate documentation from source (you might want to change the +OUTPUT_DIRECTORY configuration value found in Doxyfile). + +Requirements +------------------------------ +LuaC++ makes use of the following C++0x features, which means your favorite +compiler might not yet be able to compile and use LuaC++: + + * variadic templates + * rvalue references + * the tuple module + +Additionally, as LuaC++ uses C++ exceptions for error handling, make sure your +Lua library is compiled as C++. + +License +============================== +LuaC++ is licensed under the terms of the MIT license, see the LICENSE file for +more information. diff --git a/src/error.cpp b/src/error.cpp index bc0b6db..8d8e504 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -3,7 +3,7 @@ namespace lua { - error::error(const char* what) : std::runtime_error(what) - { - } + error::error(const char* what) : std::runtime_error(what) + { + } } diff --git a/src/object.cpp b/src/object.cpp index e70ea6b..08d3c60 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -3,20 +3,20 @@ namespace lua { - bool object::operator==(const reference& r) - { - push(); - r.push(); - bool b = lua_equal(state(), -1, -2); - lua_pop(state(), 2); - return b; - } + bool object::operator==(const reference& r) + { + push(); + r.push(); + bool b = lua_equal(state(), -1, -2); + lua_pop(state(), 2); + return b; + } - bool object::operator==(const nil_t& n) - { - push(); - bool b = lua_isnil(state(), -1); - lua_pop(state(), 1); - return b; - } + bool object::operator==(const nil_t& n) + { + push(); + bool b = lua_isnil(state(), -1); + lua_pop(state(), 1); + return b; + } } diff --git a/src/reference.cpp b/src/reference.cpp index fa3555d..f9035f2 100644 --- a/src/reference.cpp +++ b/src/reference.cpp @@ -3,55 +3,55 @@ namespace lua { - reference::reference(lua_State* L, int index) : L(L) - { - lua_pushvalue(L, index); - ref = luaL_ref(L, LUA_REGISTRYINDEX); - } - - reference::~reference() - { - luaL_unref(L, LUA_REGISTRYINDEX, ref); - } - - //for std::tuple compatibility - reference::reference() : L(0), ref(LUA_NOREF) {} - - const reference& reference::operator=(const reference& c) - { - L = c.L, ref = c.copyRef(); - return *this; - } - - reference::reference(const reference& c) - { - *this = c; - } - - void reference::push() const - { - lua_rawgeti(L, LUA_REGISTRYINDEX, ref); - } - - type::luatype reference::type() const - { - push(); - int t = lua_type(L, -1); - lua_pop(L, 1); - return static_cast(t); - } - - const char* reference::typeName() const - { - push(); - const char* s = luaL_typename(L, -1); - lua_pop(L, 1); - return s; - } - - int reference::copyRef() const - { - lua_rawgeti(L, LUA_REGISTRYINDEX, ref); - return luaL_ref(L, LUA_REGISTRYINDEX); - } + reference::reference(lua_State* L, int index) : L(L) + { + lua_pushvalue(L, index); + ref = luaL_ref(L, LUA_REGISTRYINDEX); + } + + reference::~reference() + { + luaL_unref(L, LUA_REGISTRYINDEX, ref); + } + + //for std::tuple compatibility + reference::reference() : L(0), ref(LUA_NOREF) {} + + const reference& reference::operator=(const reference& c) + { + L = c.L, ref = c.copyRef(); + return *this; + } + + reference::reference(const reference& c) + { + *this = c; + } + + void reference::push() const + { + lua_rawgeti(L, LUA_REGISTRYINDEX, ref); + } + + type::luatype reference::type() const + { + push(); + int t = lua_type(L, -1); + lua_pop(L, 1); + return static_cast(t); + } + + const char* reference::typeName() const + { + push(); + const char* s = luaL_typename(L, -1); + lua_pop(L, 1); + return s; + } + + int reference::copyRef() const + { + lua_rawgeti(L, LUA_REGISTRYINDEX, ref); + return luaL_ref(L, LUA_REGISTRYINDEX); + } } diff --git a/src/stack.cpp b/src/stack.cpp index cbfdde7..e39fad0 100644 --- a/src/stack.cpp +++ b/src/stack.cpp @@ -9,97 +9,97 @@ namespace lua { - // from Lua - void getValue(lua_State* L, int index, table& r) - { - r = table(L, index); - } - - void getValue(lua_State* L, int index, function& r) - { - r = function(L, index); - } - - void getValue(lua_State* L, int index, object& r) - { - r = object(L, index); - } - - void getValue(lua_State* L, int index, lua_Integer& r) - { - r = lua_tointeger(L, index); - } - - void getValue(lua_State* L, int index, lua_Number& r) - { - r = lua_tonumber(L, index); - } - - void getValue(lua_State* L, int index, bool& r) - { - r = lua_toboolean(L, index); - } - - void getValue(lua_State* L, int index, const char*& r) - { - r = lua_tostring(L, index); - } - - void getValue(lua_State* L, int index, const char*& r, size_t& len) - { - r = lua_tolstring(L, index, &len); - } - - void getValue(lua_State* L, int index, std::string& r) - { - size_t len; - const char* s = lua_tolstring(L, index, &len); - r = std::string(s, len); - } - - // to Lua - void pushValue(lua_State* L, reference& ref) - { - ref.push(); - } - - void pushValue(lua_State* L, lua_Integer i) - { - lua_pushinteger(L, i); - } - - void pushValue(lua_State* L, lua_Number n) - { - lua_pushnumber(L, n); - } - - void pushValue(lua_State* L, bool b) - { - lua_pushboolean(L, b); - } - - void pushValue(lua_State* L, const char* s) - { - lua_pushstring(L, s); - } - - void pushValue(lua_State* L, const char* s, size_t len) - { - lua_pushlstring(L, s, len); - } - - void pushValue(lua_State* L, const std::string& str) - { - lua_pushlstring(L, str.c_str(), str.length()); - } - - void pushValue(lua_State* L, lua_CFunction f) - { - lua_pushcfunction(L, f); - } - - void pushValue(lua_State* L, nil_t& n) - { - lua_pushnil(L); - } + // from Lua + void getValue(lua_State* L, int index, table& r) + { + r = table(L, index); + } + + void getValue(lua_State* L, int index, function& r) + { + r = function(L, index); + } + + void getValue(lua_State* L, int index, object& r) + { + r = object(L, index); + } + + void getValue(lua_State* L, int index, lua_Integer& r) + { + r = lua_tointeger(L, index); + } + + void getValue(lua_State* L, int index, lua_Number& r) + { + r = lua_tonumber(L, index); + } + + void getValue(lua_State* L, int index, bool& r) + { + r = lua_toboolean(L, index); + } + + void getValue(lua_State* L, int index, const char*& r) + { + r = lua_tostring(L, index); + } + + void getValue(lua_State* L, int index, const char*& r, size_t& len) + { + r = lua_tolstring(L, index, &len); + } + + void getValue(lua_State* L, int index, std::string& r) + { + size_t len; + const char* s = lua_tolstring(L, index, &len); + r = std::string(s, len); + } + + // to Lua + void pushValue(lua_State* L, reference& ref) + { + ref.push(); + } + + void pushValue(lua_State* L, lua_Integer i) + { + lua_pushinteger(L, i); + } + + void pushValue(lua_State* L, lua_Number n) + { + lua_pushnumber(L, n); + } + + void pushValue(lua_State* L, bool b) + { + lua_pushboolean(L, b); + } + + void pushValue(lua_State* L, const char* s) + { + lua_pushstring(L, s); + } + + void pushValue(lua_State* L, const char* s, size_t len) + { + lua_pushlstring(L, s, len); + } + + void pushValue(lua_State* L, const std::string& str) + { + lua_pushlstring(L, str.c_str(), str.length()); + } + + void pushValue(lua_State* L, lua_CFunction f) + { + lua_pushcfunction(L, f); + } + + void pushValue(lua_State* L, nil_t& n) + { + lua_pushnil(L); + } } diff --git a/src/state.cpp b/src/state.cpp index e3b06d5..96d649e 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -5,76 +5,76 @@ namespace { - int atpanic(lua_State* L) - { - throw lua::error(lua_tostring(L, -1)); - } + int atpanic(lua_State* L) + { + throw lua::error(lua_tostring(L, -1)); + } } namespace lua { - void state::init() - { - lua_atpanic(L, atpanic); + void state::init() + { + lua_atpanic(L, atpanic); - _G = table(L, LUA_GLOBALSINDEX); - _R = table(L, LUA_REGISTRYINDEX); - } + _G = table(L, LUA_GLOBALSINDEX); + _R = table(L, LUA_REGISTRYINDEX); + } - state::state() : L(luaL_newstate(), true) - { - init(); - } + state::state() : L(luaL_newstate(), true) + { + init(); + } - state::state(lua_State* L) : L(L, false) - { - init(); - } + state::state(lua_State* L) : L(L, false) + { + init(); + } - void state::openLibs() - { - luaL_openlibs(L); - } + void state::openLibs() + { + luaL_openlibs(L); + } - void state::doString(const char* code) - { - int err = luaL_dostring(L, code); - if(err) - lua_error(L); - } + void state::doString(const char* code) + { + int err = luaL_dostring(L, code); + if(err) + lua_error(L); + } - void state::doFile(const char* path) - { - int err = luaL_dofile(L, path); - if(err) - lua_error(L); - } + void state::doFile(const char* path) + { + int err = luaL_dofile(L, path); + if(err) + lua_error(L); + } - table& state::globals() - { - return _G; - } + table& state::globals() + { + return _G; + } - const table& state::globals() const - { - return _G; - } + const table& state::globals() const + { + return _G; + } - table& state::registry() - { - return _R; - } + table& state::registry() + { + return _R; + } - const table& state::registry() const - { - return _R; - } + const table& state::registry() const + { + return _R; + } - table state::newTable(int narr, int nrec) - { - lua_createtable(L, narr, nrec); - table t(L); - lua_pop(L, 1); - return t; - } + table state::newTable(int narr, int nrec) + { + lua_createtable(L, narr, nrec); + table t(L); + lua_pop(L, 1); + return t; + } } diff --git a/src/table.cpp b/src/table.cpp index 8e7207b..1fd137d 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -3,8 +3,8 @@ namespace lua { - table::table(lua_State* L, int index) : reference(L, index) - { - assertType(L, index, type::table); - } + table::table(lua_State* L, int index) : reference(L, index) + { + assertType(L, index, type::table); + } } diff --git a/test/error.cpp b/test/error.cpp index 4785b92..86e614c 100644 --- a/test/error.cpp +++ b/test/error.cpp @@ -5,20 +5,20 @@ int main() { - lua::state lua; - lua.openLibs(); + lua::state lua; + lua.openLibs(); - lua["foo"] = "bar"; + lua["foo"] = "bar"; - try - { - int i = lua["foo"]; - lua::function print = lua["print"]; - print(i); - } - catch(lua::error& err) - { - assert(std::strcmp(err.what(), "expected number, got string") == 0); - } + try + { + int i = lua["foo"]; + lua::function print = lua["print"]; + print(i); + } + catch(lua::error& err) + { + assert(std::strcmp(err.what(), "expected number, got string") == 0); + } } diff --git a/test/exceptionhandler.cpp b/test/exceptionhandler.cpp index 38a8557..e8ab13b 100644 --- a/test/exceptionhandler.cpp +++ b/test/exceptionhandler.cpp @@ -4,33 +4,33 @@ namespace { - void globalexcept() - { - try - { - throw; - } - catch(std::exception& ex) - { - std::cerr << "Unhandled exception :: " << ex.what() << std::endl; - } - catch(...) - { - std::cerr << "Unknown exception occurred\n"; - std::abort(); - } + void globalexcept() + { + try + { + throw; + } + catch(std::exception& ex) + { + std::cerr << "Unhandled exception :: " << ex.what() << std::endl; + } + catch(...) + { + std::cerr << "Unknown exception occurred\n"; + std::abort(); + } - std::exit(1); - } + std::exit(1); + } - class _registerExceptionHandler - { - public: - _registerExceptionHandler() - { - std::set_terminate(globalexcept); - } - }; + class _registerExceptionHandler + { + public: + _registerExceptionHandler() + { + std::set_terminate(globalexcept); + } + }; - _registerExceptionHandler regExcptHandler; + _registerExceptionHandler regExcptHandler; } diff --git a/test/functions.cpp b/test/functions.cpp index 83ba95c..64f3d07 100644 --- a/test/functions.cpp +++ b/test/functions.cpp @@ -2,30 +2,30 @@ double mul(double a, double b) { - return a * b; + return a * b; } std::string quotify(std::string a) { - return '"' + a + '"'; + return '"' + a + '"'; } const char* getTestField(lua::table t) { - return t["test"]; + return t["test"]; } int main() { - lua::state lua; - lua.openLibs(); + lua::state lua; + lua.openLibs(); - lua["mul"] = mul; - lua.doString("assert(mul(3, 2) == 3 * 2)"); + lua["mul"] = mul; + lua.doString("assert(mul(3, 2) == 3 * 2)"); - lua["quotify"] = quotify; - lua.doString("assert(quotify('foo') == '\"foo\"')"); + lua["quotify"] = quotify; + lua.doString("assert(quotify('foo') == '\"foo\"')"); - lua["getTestField"] = getTestField; - lua.doString("assert(getTestField{test = 'foo'} == 'foo')"); + lua["getTestField"] = getTestField; + lua.doString("assert(getTestField{test = 'foo'} == 'foo')"); } diff --git a/test/multiple_returns.cpp b/test/multiple_returns.cpp index fdd2372..0b2afb7 100644 --- a/test/multiple_returns.cpp +++ b/test/multiple_returns.cpp @@ -7,13 +7,13 @@ int main() { - lua::state lua; - lua.doString("function test() return 42, 'hello' end"); + lua::state lua; + lua.doString("function test() return 42, 'hello' end"); - lua::function test = lua["test"]; + lua::function test = lua["test"]; - auto ret = test.call(); // returns std::tuple + auto ret = test.call(); // returns std::tuple - assert(std::get<0>(ret) == 42); - assert(std::strcmp(std::get<1>(ret), "hello") == 0); + assert(std::get<0>(ret) == 42); + assert(std::strcmp(std::get<1>(ret), "hello") == 0); } diff --git a/test/nil.cpp b/test/nil.cpp index e1e9127..ad7939b 100644 --- a/test/nil.cpp +++ b/test/nil.cpp @@ -4,13 +4,13 @@ int main() { - lua::state lua; + lua::state lua; - lua["foo"] = 1; - assert(static_cast(lua["foo"]) == 1); + lua["foo"] = 1; + assert(static_cast(lua["foo"]) == 1); - lua["foo"] = lua::nil; - lua::object foo = lua["foo"]; + lua["foo"] = lua::nil; + lua::object foo = lua["foo"]; - assert(foo == lua::nil); + assert(foo == lua::nil); } From a6758a962c05af78d07ee17e3c47f76331e0e8e8 Mon Sep 17 00:00:00 2001 From: Josh Simmons Date: Sun, 16 Dec 2012 19:04:37 +1100 Subject: [PATCH 2/3] Kill some annoying unused variable warnings. --- luacpp/function.hpp | 5 ++++- luacpp/stack.hpp | 7 ++++++- luacpp/table.hpp | 7 ++++++- luacpp/types.hpp | 8 ++++++++ src/object.cpp | 2 ++ src/stack.cpp | 2 ++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/luacpp/function.hpp b/luacpp/function.hpp index b3a29fe..6e96360 100644 --- a/luacpp/function.hpp +++ b/luacpp/function.hpp @@ -72,7 +72,10 @@ namespace lua pushArg(L, args...); } - void pushArg(lua_State* L){} + void pushArg(lua_State* L) + { + (void)(L); // Unused. + } }; } diff --git a/luacpp/stack.hpp b/luacpp/stack.hpp index eb0e204..4e18e73 100644 --- a/luacpp/stack.hpp +++ b/luacpp/stack.hpp @@ -70,7 +70,11 @@ namespace lua template struct luaToTuple<0, Args...> { - static void fill(lua_State* L, std::tuple& args) {} + static void fill(lua_State* L, std::tuple& args) + { + (void)(L); // Unused. + (void)(args); // Unused. + } }; // regular single return value @@ -91,6 +95,7 @@ namespace lua { static int call(lua_State* L, void (*f)(Args...), std::tuple& args) { + (void)(L); // Unused. tuplecall::call(f, args); return 0; } diff --git a/luacpp/table.hpp b/luacpp/table.hpp index 1c4f4f7..2c70af5 100644 --- a/luacpp/table.hpp +++ b/luacpp/table.hpp @@ -11,11 +11,16 @@ namespace lua template inline void checkType(lua_State* L, int index) { + (void)(index); // Unused. assertType(L, -1, typeOf(L)); } template<> - inline void checkType(lua_State* L, int index) {} + inline void checkType(lua_State* L, int index) + { + (void)(L); + (void)(index); + } ///Lua table /** diff --git a/luacpp/types.hpp b/luacpp/types.hpp index d08c627..b75e977 100644 --- a/luacpp/types.hpp +++ b/luacpp/types.hpp @@ -37,48 +37,56 @@ namespace lua template inline type::luatype typeOf(lua_State* L) { + (void)(L); // Unused. return type::none; } template<> inline type::luatype typeOf
(lua_State* L) { + (void)(L); // Unused. return type::table; } template<> inline type::luatype typeOf(lua_State* L) { + (void)(L); // Unused. return type::function; } template<> inline type::luatype typeOf(lua_State* L) { + (void)(L); // Unused. return type::number; } template<> inline type::luatype typeOf(lua_State* L) { + (void)(L); // Unused. return type::number; } template<> inline type::luatype typeOf(lua_State* L) { + (void)(L); // Unused. return type::boolean; } template<> inline type::luatype typeOf(lua_State* L) { + (void)(L); // Unused. return type::string; } template<> inline type::luatype typeOf(lua_State* L) { + (void)(L); // Unused. return type::string; } } diff --git a/src/object.cpp b/src/object.cpp index 08d3c60..c0c10f7 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -14,6 +14,8 @@ namespace lua bool object::operator==(const nil_t& n) { + (void)(n); // Unused. + push(); bool b = lua_isnil(state(), -1); lua_pop(state(), 1); diff --git a/src/stack.cpp b/src/stack.cpp index e39fad0..286d775 100644 --- a/src/stack.cpp +++ b/src/stack.cpp @@ -60,6 +60,7 @@ namespace lua // to Lua void pushValue(lua_State* L, reference& ref) { + (void)(L); // Unused. ref.push(); } @@ -100,6 +101,7 @@ namespace lua void pushValue(lua_State* L, nil_t& n) { + (void)(n); // Unused. lua_pushnil(L); } } From b626095a181c9e20b31ef8275cb95caeb5c7edd6 Mon Sep 17 00:00:00 2001 From: Josh Simmons Date: Sun, 16 Dec 2012 19:12:31 +1100 Subject: [PATCH 3/3] Fix warning about mixed struct/class definitions. --- luacpp/nil.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luacpp/nil.hpp b/luacpp/nil.hpp index f6dd04c..611f7d8 100644 --- a/luacpp/nil.hpp +++ b/luacpp/nil.hpp @@ -7,7 +7,7 @@ namespace lua /** Use the constant lua::nil. */ - struct nil_t + class nil_t { };