From 6b6efccb664e9d9b82e82e9d322f90282cd3c127 Mon Sep 17 00:00:00 2001 From: Peter Ferenc Hajdu Date: Mon, 29 Sep 2014 13:04:48 +0200 Subject: [PATCH 1/4] fix tautological compare error --- sol/function_types.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sol/function_types.hpp b/sol/function_types.hpp index 8ea6c390..e28733e7 100644 --- a/sol/function_types.hpp +++ b/sol/function_types.hpp @@ -247,7 +247,7 @@ struct base_function { return base_gc(L, *pudata); } - template + template struct userdata { static int call(lua_State* L) { // Zero-based template parameter, but upvalues start at 1 @@ -259,7 +259,7 @@ struct base_function { } static int gc(lua_State* L) { - for(std::size_t i = 0; i < I; ++i) { + for(int i = 0; i < I; ++i) { upvalue_t up = stack::get(L, i + 1); base_function* obj = static_cast(up.value); std::allocator alloc{}; From 351c5af8f64ff77f016df56645669f0e4378872e Mon Sep 17 00:00:00 2001 From: Rapptz Date: Mon, 29 Sep 2014 22:24:32 -0400 Subject: [PATCH 2/4] Fix implicit conversion warnings for getter. --- sol/stack.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sol/stack.hpp b/sol/stack.hpp index 55c1cacc..c552aa55 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -92,12 +92,12 @@ template struct getter { template> = 0> static U get(lua_State* L, int index = -1) { - return lua_tonumber(L, index); + return static_cast(lua_tonumber(L, index)); } template, std::is_signed> = 0> static U get(lua_State* L, int index = -1) { - return lua_tounsigned(L, index); + return static_cast(lua_tounsigned(L, index)); } template, std::is_unsigned> = 0> @@ -146,7 +146,7 @@ struct getter { static std::string get(lua_State* L, int index = -1) { std::string::size_type len; auto str = lua_tolstring(L, index, &len); - return{ str, len }; + return { str, len }; } }; From c83d1941db47e4739e470a93663b372c2a41bf9a Mon Sep 17 00:00:00 2001 From: mp4 Date: Sun, 11 Jan 2015 00:28:30 -0700 Subject: [PATCH 3/4] added tutorial on reading in values from lua table to c++ --- examples/tables.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 examples/tables.cpp diff --git a/examples/tables.cpp b/examples/tables.cpp new file mode 100644 index 00000000..17c9e117 --- /dev/null +++ b/examples/tables.cpp @@ -0,0 +1,36 @@ +#include +#include +#include + +/// this example shows how to read data in from a lua table +using namespace std; + +//compiles on linux with: g++ -std=c++11 -I.. table.cpp -o tables -llua + +int main(int argc, char * argv[]) +{ + sol::state lua; + //table used as an array + lua.script("table1 = {\"hello\", \"table\"}"); + //table with a nested table and the key value syntax + lua.script("table2 = {[\"nestedTable\"]={[\"key1\"]=\"value1\", [\"key2\"]=\"value2\"}," + " [\"name\"]=\"table2\"}"); + + + //using the values stored in table1 + cout << lua.get("table1").get(1)<< " " << + lua.get("table1").get(2) << endl; + + auto t2 = lua.get("table2"); + auto nestedTable = t2.get("nestedTable"); + //some retrival of values from the nested table + //the cleaner way of doing things + cout << "nested table: key1 : " << nestedTable.get("key1") << ", key2: " + //yes you can chain the get<>() results + << lua.get("table2").get("nestedTable").get("key2") + << endl; + + cout << "name of t2: " << t2.get("name") << endl; + + return 0; +} \ No newline at end of file From f6fb0fd7f02657e6a0d35e9acd2cae42d833a28c Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 15 Jan 2015 11:53:15 -0500 Subject: [PATCH 4/4] Improve formatting of table example --- examples/tables.cpp | 60 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/examples/tables.cpp b/examples/tables.cpp index 17c9e117..be2dfde9 100644 --- a/examples/tables.cpp +++ b/examples/tables.cpp @@ -2,35 +2,35 @@ #include #include -/// this example shows how to read data in from a lua table -using namespace std; +// this example shows how to read data in from a lua table -//compiles on linux with: g++ -std=c++11 -I.. table.cpp -o tables -llua +int main() { + sol::state lua; + // table used as an array + lua.script("table1 = {\"hello\", \"table\"}"); + // table with a nested table and the key value syntax + lua.script("table2 = {" + "[\"nestedTable\"] = {" + "[\"key1\"] = \"value1\"," + "[\"key2\"]= \"value2\"" + "}," + "[\"name\"]= \"table2\"" + "}"); -int main(int argc, char * argv[]) -{ - sol::state lua; - //table used as an array - lua.script("table1 = {\"hello\", \"table\"}"); - //table with a nested table and the key value syntax - lua.script("table2 = {[\"nestedTable\"]={[\"key1\"]=\"value1\", [\"key2\"]=\"value2\"}," - " [\"name\"]=\"table2\"}"); - - - //using the values stored in table1 - cout << lua.get("table1").get(1)<< " " << - lua.get("table1").get(2) << endl; - - auto t2 = lua.get("table2"); - auto nestedTable = t2.get("nestedTable"); - //some retrival of values from the nested table - //the cleaner way of doing things - cout << "nested table: key1 : " << nestedTable.get("key1") << ", key2: " - //yes you can chain the get<>() results - << lua.get("table2").get("nestedTable").get("key2") - << endl; - - cout << "name of t2: " << t2.get("name") << endl; - - return 0; -} \ No newline at end of file + + // using the values stored in table1 + std::cout << lua.get("table1").get(1) << " " + << lua.get("table1").get(2) << '\n'; + + auto t2 = lua.get("table2"); + auto nestedTable = t2.get("nestedTable"); + + // some retrieval of values from the nested table + // the cleaner way of doing things + std::cout << "nested table: key1 : " << nestedTable.get("key1") << ", key2: " + // yes you can chain the get<>() results + << lua.get("table2").get("nestedTable").get("key2") + << '\n'; + + std::cout << "name of t2: " << t2.get("name") << '\n'; +}