From fc19896815726ca67fe4110cc0b7b22c79c6b2a1 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 06:10:30 -0500 Subject: [PATCH 01/15] Some changes to make sure builds go through on 64-bit. --- sol/function.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sol/function.hpp b/sol/function.hpp index fcdedc47..ebb730f9 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -42,11 +42,11 @@ private: } void call(types, std::size_t n) { - lua_pcall(state(), n, 0, 0); + lua_pcall(state(), static_cast(n), 0, 0); } void call(types<>, std::size_t n) { - lua_pcall(state(), n, 0, 0); + lua_pcall(state(), static_cast(n), 0, 0); } public: From a5d14580b13d42fb0144e1dfc2df2fc06e91a698 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 06:34:18 -0500 Subject: [PATCH 02/15] Adding sol.scratch.cpp, and will also add CATCH for tests. --- .gitignore | 2 -- sol.scratch.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 sol.scratch.cpp diff --git a/.gitignore b/.gitignore index 2cf6d7dd..7355685a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,6 @@ bin/* demacro.txt Shinobi2 dev.* -main.cpp -sol.scratch.cpp lua-5.2.2/ Debug/ Release/ diff --git a/sol.scratch.cpp b/sol.scratch.cpp new file mode 100644 index 00000000..b12fb7fa --- /dev/null +++ b/sol.scratch.cpp @@ -0,0 +1,66 @@ +#include +#include +#include + +std::string free_func_yo() { + std::cout << "free_func_yo()" << std::endl; + return "test"; +} + +struct member_test { + + std::string operator() () { + std::cout << "member_test()" << std::endl; + return "test"; + } + +}; + +void run_test(sol::state& lua) { + lua.script("assert(os.fun() == \"test\")\n" + "assert(os.name == \"windows\")"); +} + +int main( ) { + sol::state lua; + lua.open_libraries( sol::lib::base, sol::lib::os ); + + lua.get( "os" ).set( "name", "windows" ); + + lua.get( "os" ).set_function( "fun", + [ ] ( ) { + std::cout << "stateless lambda()" << std::endl; + return "test"; + } + ); + run_test( lua ); + + lua.get( "os" ).set_function( "fun", &free_func_yo ); + run_test( lua ); + + // l-value, can optomize + auto lval = member_test( ); + lua.get( "os" ).set_function( "fun", &member_test::operator(), lval ); + run_test( lua ); + + // Tests will begin failing here + // stateful lambda: non-convertible, unoptomizable + int breakit = 50; + lua.get( "os" ).set_function( "fun", + [ &breakit ] ( ) { + std::cout << "stateless lambda()" << std::endl; + return "test"; + } + ); + run_test( lua ); + + // r-value, cannot optomize + lua.get( "os" ).set_function( "fun", &member_test::operator(), member_test( ) ); + run_test( lua ); + + // r-value, cannot optomize + auto rval = member_test( ); + lua.get( "os" ).set_function( "fun", &member_test::operator(), std::move( rval ) ); + run_test( lua ); + +} \ No newline at end of file From e7f8ec9e5ca6f6a191a1c4cf0fac139401c875f3 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 06:38:25 -0500 Subject: [PATCH 03/15] CATCH for tests. --- .gitmodules | 3 +++ Catch | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 Catch diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..1c1a2167 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Catch"] + path = Catch + url = https://github.com/philsquared/Catch.git diff --git a/Catch b/Catch new file mode 160000 index 00000000..a6d74bd5 --- /dev/null +++ b/Catch @@ -0,0 +1 @@ +Subproject commit a6d74bd55aeff9a2506906e451305364f7a02d34 From dd63621453841e08bb84f145f3138ef6462abe83 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 08:32:27 -0500 Subject: [PATCH 04/15] Added some catch tests and a basic nil getter. --- sol.scratch.cpp | 86 +++++++++++++++++++++++++++++++++++++------------ sol/stack.hpp | 14 +++++++- 2 files changed, 78 insertions(+), 22 deletions(-) diff --git a/sol.scratch.cpp b/sol.scratch.cpp index b12fb7fa..c5affbdc 100644 --- a/sol.scratch.cpp +++ b/sol.scratch.cpp @@ -1,13 +1,13 @@ +#define CATCH_CONFIG_MAIN +#include #include -#include -#include -std::string free_func_yo() { - std::cout << "free_func_yo()" << std::endl; +std::string free_function() { + std::cout << "free_function()" << std::endl; return "test"; } -struct member_test { +struct object { std::string operator() () { std::cout << "member_test()" << std::endl; @@ -16,32 +16,75 @@ struct member_test { }; -void run_test(sol::state& lua) { +void run_script(sol::state& lua) { lua.script("assert(os.fun() == \"test\")\n" "assert(os.name == \"windows\")"); } -int main( ) { +TEST_CASE( "simple/set_global", "Check if the set_global works properly." ) { sol::state lua; - lua.open_libraries( sol::lib::base, sol::lib::os ); + lua.set( "a", 9 ); + REQUIRE_NOTHROW( lua.script( "if a ~= 9 then error('wrong value') end" ) ); + + lua.set( "d", "hello" ); + REQUIRE_NOTHROW( lua.script( "if d ~= 'hello' then error('expected \\'hello\\', got '.. tostring(d)) end" ) ); + + lua.set( "e", std::string( "hello" ) ); + REQUIRE_NOTHROW( lua.script( "if d ~= 'hello' then error('expected \\'hello\\', got '.. tostring(d)) end" ) ); + + lua.set( "f", true ); + REQUIRE_NOTHROW( lua.script( "if f ~= true then error('wrong value') end" ) ); +} + +TEST_CASE( "simple/get", "Tests if the get function works properly." ) { + sol::state lua; + + lua.script( "a = 9" ); + auto a = lua.get( "a" ); + REQUIRE( a == 9.0 ); + + lua.script( "b = nil" ); + REQUIRE_NOTHROW( auto b = lua.get( "b" ) ); + + lua.script( "d = 'hello'" ); + auto d = lua.get( "d" ); + REQUIRE( d == "hello" ); + + lua.script( "e = true" ); + auto e = lua.get( "e" ); + REQUIRE( e == true ); +} + +TEST_CASE( "simple/addition", "" ) { + sol::state lua; + + lua.set( "b", 0.2 ); + lua.script( "c = 9 + b" ); + auto c = lua.get( "c" ); + + REQUIRE( c == 9.2 ); +} + +/* lua.get( "os" ).set( "name", "windows" ); + SECTION( "" ) lua.get( "os" ).set_function( "fun", [ ] ( ) { std::cout << "stateless lambda()" << std::endl; return "test"; } ); - run_test( lua ); + run_script( lua ); - lua.get( "os" ).set_function( "fun", &free_func_yo ); - run_test( lua ); + lua.get( "os" ).set_function( "fun", &free_function ); + run_script( lua ); // l-value, can optomize - auto lval = member_test( ); - lua.get( "os" ).set_function( "fun", &member_test::operator(), lval ); - run_test( lua ); + auto lval = object( ); + lua.get( "os" ).set_function( "fun", &object::operator(), lval ); + run_script( lua ); // Tests will begin failing here // stateful lambda: non-convertible, unoptomizable @@ -52,15 +95,16 @@ int main( ) { return "test"; } ); - run_test( lua ); + run_script( lua ); // r-value, cannot optomize - lua.get( "os" ).set_function( "fun", &member_test::operator(), member_test( ) ); - run_test( lua ); + lua.get( "os" ).set_function( "fun", &object::operator(), object( ) ); + run_script( lua ); // r-value, cannot optomize - auto rval = member_test( ); - lua.get( "os" ).set_function( "fun", &member_test::operator(), std::move( rval ) ); - run_test( lua ); + auto rval = object( ); + lua.get( "os" ).set_function( "fun", &object::operator(), std::move( rval ) ); + run_script( lua ); -} \ No newline at end of file +} +*/ diff --git a/sol/stack.hpp b/sol/stack.hpp index 1fa8a024..dc8cd811 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -45,7 +45,7 @@ inline T get_unsigned(lua_State* L, std::true_type, int index = -1) { template inline T get_unsigned(lua_State* L, std::false_type, int index = -1) { - return lua_tointeger(L, index); + return static_cast( lua_tointeger(L, index) ); } template @@ -62,6 +62,18 @@ inline T get_arithmetic(lua_State* L, std::true_type, int index = -1) { template inline T get_helper(lua_State* L, std::true_type, int index = -1) { + return get_nil(L, std::is_same(), index); +} + +template +inline T get_nil(lua_State* L, std::true_type, int index = -1) { + if (lua_isnil(L, index) == 0) + throw sol::sol_error("not nil"); + return nil_t{}; +} + +template +inline T get_nil(lua_State* L, std::false_type, int index = -1) { // T is a class type return T(L, index); } From 350f430d7428db8a8c9869fd8a0c02b231ce7924 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 11:18:13 -0500 Subject: [PATCH 05/15] Improved tests, added a build.ninja for TeamCity, and fixed formatting again to work with Rapptz's style. --- .gitignore | 3 +- build.ninja | 27 ++++++ sol.scratch.cpp | 213 ++++++++++++++++++++++++++++++------------- sol/function.hpp | 16 ++-- sol/lua_function.hpp | 72 +++++++-------- sol/stack.hpp | 28 +++--- sol/state.hpp | 12 ++- sol/table.hpp | 4 +- 8 files changed, 250 insertions(+), 125 deletions(-) create mode 100644 build.ninja diff --git a/.gitignore b/.gitignore index 7355685a..bfbe70a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ obj/* bin/* -*.ninja* demacro.txt Shinobi2 dev.* @@ -16,3 +15,5 @@ x64/ *.sln *.gitattributes liblua.a +sol/include/ +.ninja* diff --git a/build.ninja b/build.ninja new file mode 100644 index 00000000..c6a0c4a9 --- /dev/null +++ b/build.ninja @@ -0,0 +1,27 @@ +# This file has been generated by shinobi version 0.9.5 + +ninja_required_version = 1.3 +builddir = bin +objdir = obj +cxx = g++ +cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG +incflags = -I"." -I"./include" -I"." -I"./lua-5.2.2/src/" -I"./Catch/include/" +linkflags = -static liblua.a -L"./lib" + +rule compile + command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags + deps = gcc + depfile = $out.d + description = Compiling $in + +rule link + command = $cxx $in -o $out $linkflags + description = Creating $out + +build $objdir/sol.scratch.o: compile sol.scratch.cpp + +build $builddir/sol.scratch: link $objdir/sol.scratch.o + +build install: phony $builddir/sol.scratch + +default install diff --git a/sol.scratch.cpp b/sol.scratch.cpp index c5affbdc..fb968850 100644 --- a/sol.scratch.cpp +++ b/sol.scratch.cpp @@ -16,95 +16,184 @@ struct object { }; +int plop_xyz(int x, int y, std::string z) { + std::cout << x << " " << y << " " << z << std::endl; + return 11; +} + void run_script(sol::state& lua) { lua.script("assert(os.fun() == \"test\")\n" "assert(os.name == \"windows\")"); } -TEST_CASE( "simple/set_global", "Check if the set_global works properly." ) { - sol::state lua; +TEST_CASE("simple/set_global", "Check if the set_global works properly.") { + sol::state lua; - lua.set( "a", 9 ); - REQUIRE_NOTHROW( lua.script( "if a ~= 9 then error('wrong value') end" ) ); + lua.set("a", 9); + REQUIRE_NOTHROW(lua.script("if a ~= 9 then error('wrong value') end")); - lua.set( "d", "hello" ); - REQUIRE_NOTHROW( lua.script( "if d ~= 'hello' then error('expected \\'hello\\', got '.. tostring(d)) end" ) ); + lua.set("d", "hello"); + REQUIRE_NOTHROW(lua.script("if d ~= 'hello' then error('expected \\'hello\\', got '.. tostring(d)) end")); - lua.set( "e", std::string( "hello" ) ); - REQUIRE_NOTHROW( lua.script( "if d ~= 'hello' then error('expected \\'hello\\', got '.. tostring(d)) end" ) ); + lua.set("e", std::string("hello")); + REQUIRE_NOTHROW(lua.script("if d ~= 'hello' then error('expected \\'hello\\', got '.. tostring(d)) end")); - lua.set( "f", true ); - REQUIRE_NOTHROW( lua.script( "if f ~= true then error('wrong value') end" ) ); + lua.set("f", true); + REQUIRE_NOTHROW(lua.script("if f ~= true then error('wrong value') end")); } -TEST_CASE( "simple/get", "Tests if the get function works properly." ) { - sol::state lua; +TEST_CASE("simple/get", "Tests if the get function works properly.") { + sol::state lua; - lua.script( "a = 9" ); - auto a = lua.get( "a" ); - REQUIRE( a == 9.0 ); + lua.script("a = 9"); + auto a = lua.get("a"); + REQUIRE(a == 9.0); - lua.script( "b = nil" ); - REQUIRE_NOTHROW( auto b = lua.get( "b" ) ); - - lua.script( "d = 'hello'" ); - auto d = lua.get( "d" ); - REQUIRE( d == "hello" ); + lua.script("b = nil"); + REQUIRE_NOTHROW(auto b = lua.get("b")); + + lua.script("d = 'hello'"); + auto d = lua.get("d"); + REQUIRE(d == "hello"); - lua.script( "e = true" ); - auto e = lua.get( "e" ); - REQUIRE( e == true ); + lua.script("e = true"); + auto e = lua.get("e"); + REQUIRE(e == true); } -TEST_CASE( "simple/addition", "" ) { - sol::state lua; +TEST_CASE("simple/addition", "") { + sol::state lua; - lua.set( "b", 0.2 ); - lua.script( "c = 9 + b" ); - auto c = lua.get( "c" ); + lua.set("b", 0.2); + lua.script("c = 9 + b"); + auto c = lua.get("c"); - REQUIRE( c == 9.2 ); + REQUIRE(c == 9.2); +} + +TEST_CASE("simple/if", "") { + sol::state lua; + + std::string program = "if true then f = 0.1 else f = 'test' end"; + lua.script(program); + auto f = lua.get("f"); + + REQUIRE(f == 0.1); +} + +TEST_CASE("simple/evalStream", "The VM evaluates a stream's contents using a reader") { + sol::state lua; + + std::stringstream sscript; + int g = 9; + sscript << "g = " << g << ";"; + + REQUIRE_NOTHROW(lua.script(sscript.str())); + REQUIRE(lua.get("g") == 9.0); +} + +TEST_CASE("simple/callWithParameters", "Lua function is called with a few parameters from C++") { + sol::state lua; + + REQUIRE_NOTHROW(lua.script("function my_add(i, j, k) return i + j + k end")); + auto f = lua.get("my_add"); + REQUIRE_NOTHROW(f.call(1, 2, 3)); + REQUIRE_THROWS(f.call(1, 2, "arf")); +} + +TEST_CASE("simple/callCppFunction", "C++ function is called from lua") { + sol::state lua; + + lua.set_function("plop_xyz", plop_xyz); + lua.script("x = plop_xyz(2, 6, 'hello')"); + + REQUIRE(lua.get("x") == 11); +} + +TEST_CASE("simple/callLambda", "A C++ lambda is exposed to lua and called") { + sol::state lua; + + int x = 0; + + lua.set_function("foo", [ &x ] { x = 1; }); + + lua.script("foo()"); + + REQUIRE(x == 1); +} + +TEST_CASE("advanced/callLambdaReturns", "Checks for lambdas returning values") { + sol::state lua; + + lua.set_function("a", [ ] { return 42; }); + lua.set_function("b", [ ] { return 42u; }); + lua.set_function("c", [ ] { return 3.14; }); + lua.set_function("d", [ ] { return 6.28f; }); + lua.set_function("e", [ ] { return "lol"; }); + lua.set_function("f", [ ] { return true; }); + lua.set_function("g", [ ] { return std::string("str"); }); + lua.set_function("h", [ ] { }); + lua.set_function("i", [ ] { return sol::nil; }); +} + +TEST_CASE("advanced/callLambda2", "A C++ lambda is exposed to lua and called") { + sol::state lua; + + int x = 0; + lua.set_function("set_x", [ &] (int new_x) { + x = new_x; + return 0; + }); + + lua.script("set_x(9)"); + REQUIRE(x == 9); +} + +TEST_CASE("negative/basicError", "Check if error handling works correctly") { + sol::state lua; + + REQUIRE_THROWS(lua.script("nil[5]")); } /* - lua.get( "os" ).set( "name", "windows" ); + lua.get("os").set("name", "windows"); - SECTION( "" ) - lua.get( "os" ).set_function( "fun", - [ ] ( ) { - std::cout << "stateless lambda()" << std::endl; - return "test"; - } - ); - run_script( lua ); + SECTION("") + lua.get("os").set_function("fun", + [ ] () { + std::cout << "stateless lambda()" << std::endl; + return "test"; + } + ); + run_script(lua); - lua.get( "os" ).set_function( "fun", &free_function ); - run_script( lua ); + lua.get("os").set_function("fun", &free_function); + run_script(lua); - // l-value, can optomize - auto lval = object( ); - lua.get( "os" ).set_function( "fun", &object::operator(), lval ); - run_script( lua ); + // l-value, can optomize + auto lval = object(); + lua.get("os").set_function("fun", &object::operator(), lval); + run_script(lua); - // Tests will begin failing here - // stateful lambda: non-convertible, unoptomizable - int breakit = 50; - lua.get( "os" ).set_function( "fun", - [ &breakit ] ( ) { - std::cout << "stateless lambda()" << std::endl; - return "test"; - } - ); - run_script( lua ); + // Tests will begin failing here + // stateful lambda: non-convertible, unoptomizable + int breakit = 50; + lua.get("os").set_function("fun", + [ &breakit ] () { + std::cout << "stateless lambda()" << std::endl; + return "test"; + } + ); + run_script(lua); - // r-value, cannot optomize - lua.get( "os" ).set_function( "fun", &object::operator(), object( ) ); - run_script( lua ); + // r-value, cannot optomize + lua.get("os").set_function("fun", &object::operator(), object()); + run_script(lua); - // r-value, cannot optomize - auto rval = object( ); - lua.get( "os" ).set_function( "fun", &object::operator(), std::move( rval ) ); - run_script( lua ); + // r-value, cannot optomize + auto rval = object(); + lua.get("os").set_function("fun", &object::operator(), std::move(rval)); + run_script(lua); } */ diff --git a/sol/function.hpp b/sol/function.hpp index ebb730f9..edf44337 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -30,22 +30,22 @@ namespace sol { class function : virtual public reference { private: template - std::tuple call(types, std::size_t n) { - lua_pcall(state(), n, sizeof...(Ret), 0); + std::tuple invoke(types, std::size_t n) { + lua_pcall(state(), static_cast(n), sizeof...(Ret), 0); return stack::pop_call(state(), std::make_tuple, types()); } template - Ret call(types, std::size_t n) { - lua_pcall(state(), n, 1, 0); + Ret invoke(types, std::size_t n) { + lua_pcall(state(), static_cast(n), 1, 0); return stack::pop(state()); } - void call(types, std::size_t n) { + void invoke(types, std::size_t n) { lua_pcall(state(), static_cast(n), 0, 0); } - void call(types<>, std::size_t n) { + void invoke(types<>, std::size_t n) { lua_pcall(state(), static_cast(n), 0, 0); } @@ -56,10 +56,10 @@ public: } template - auto invoke(Args&&... args) -> decltype(call(types(), sizeof...(Args))) { + auto call(Args&&... args) -> decltype(invoke(types(), sizeof...(Args))) { push(); stack::push_args(state(), std::forward(args)...); - return call(types(), sizeof...(Args)); + return invoke(types(), sizeof...(Args)); } }; } // sol diff --git a/sol/lua_function.hpp b/sol/lua_function.hpp index 61a5249d..e73f818e 100644 --- a/sol/lua_function.hpp +++ b/sol/lua_function.hpp @@ -29,32 +29,32 @@ namespace sol { namespace detail { template -void get_upvalue_ptr( lua_State* L, T*& data, std::size_t datasize, std::array voiddata, int& upvalue ) { - for ( std::size_t i = 0, d = 0; d < datasize; ++i, d += sizeof( void* ) ) { - voiddata[ i ] = lua_touserdata( L, lua_upvalueindex( upvalue++ ) ); - } - data = reinterpret_cast( static_cast( voiddata.data( ) ) ); +void get_upvalue_ptr(lua_State* L, T*& data, std::size_t datasize, std::array voiddata, int& upvalue) { + for (std::size_t i = 0, d = 0; d < datasize; ++i, d += sizeof(void*)) { + voiddata[ i ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); + } + data = reinterpret_cast(static_cast(voiddata.data())); } template -void get_upvalue_ptr( lua_State* L, T*& data, std::array voiddata, int& upvalue ) { - get_upvalue_ptr( L, data, sizeof( T ), voiddata, upvalue ); +void get_upvalue_ptr(lua_State* L, T*& data, std::array voiddata, int& upvalue) { + get_upvalue_ptr(L, data, sizeof(T), voiddata, upvalue); } template -void get_upvalue_ptr( lua_State* L, T*& data, int& upvalue ) { - const static std::size_t data_t_count = ( sizeof(T)+( sizeof(void*)-1 ) ) / sizeof( void* ); - typedef std::array data_t; - data_t voiddata{{}}; - return get_upvalue_ptr(L, data, voiddata, upvalue); +void get_upvalue_ptr(lua_State* L, T*& data, int& upvalue) { + const static std::size_t data_t_count = (sizeof(T)+(sizeof(void*)-1)) / sizeof(void*); + typedef std::array data_t; + data_t voiddata{{}}; + return get_upvalue_ptr(L, data, voiddata, upvalue); } template -void get_upvalue( lua_State* L, T& data, int& upvalue ) { - const static std::size_t data_t_count = ( sizeof(T)+( sizeof(void*)-1 ) ) / sizeof( void* ); - typedef std::array data_t; - data_t voiddata{ { } }; - for ( std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof( void* ) ) { - voiddata[ i ] = lua_touserdata( L, lua_upvalueindex( upvalue++ ) ); - } - data = *reinterpret_cast( static_cast( voiddata.data( ) ) ); +void get_upvalue(lua_State* L, T& data, int& upvalue) { + const static std::size_t data_t_count = (sizeof(T)+(sizeof(void*)-1)) / sizeof(void*); + typedef std::array data_t; + data_t voiddata{ { } }; + for (std::size_t i = 0, d = 0; d < sizeof(T); ++i, d += sizeof(void*)) { + voiddata[ i ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); + } + data = *reinterpret_cast(static_cast(voiddata.data())); } } // detail @@ -80,7 +80,7 @@ struct static_lua_func { static int call(lua_State* L) { int upvalue = 1; fx_t* fx; - detail::get_upvalue( L, fx, upvalue ); + detail::get_upvalue(L, fx, upvalue); int r = typed_call(tuple_types(), typename fx_traits::args_type(), fx, L); return r; } @@ -105,8 +105,8 @@ struct static_object_lua_func { template static int typed_call(types, types, T& item, fx_t& ifx, lua_State* L) { auto fx = [ &item, &ifx ] (Args&&... args) -> TR { - return (item.*ifx)(std::forward(args)...); - }; + return (item.*ifx)(std::forward(args)...); + }; auto r = stack::pop_call(L, fx, types()); stack::push(L, std::move(r)); return 1; @@ -121,19 +121,19 @@ struct static_object_lua_func { } static int call(lua_State* L) { - const static std::size_t data_t_count = ( sizeof(fx_t)+( sizeof(void*)-1 ) ) / sizeof( void* ); - typedef std::array data_t; - int upvalue = 1; - data_t data = { { } }; - fx_t* fxptr; - for ( std::size_t i = 0, d = 0; d < sizeof(fx_t*); ++i, d += sizeof( void* ) ) { - data[ i ] = lua_touserdata( L, lua_upvalueindex( upvalue++ ) ); - } - fxptr = reinterpret_cast( static_cast( data.data( ) ) ); - fx_t& mem_ptr = *fxptr; - void* objectdata = lua_touserdata( L, lua_upvalueindex( upvalue++ ) ); - T& obj = *static_cast( objectdata ); - int r = typed_call( tuple_types( ), typename fx_traits::args_type( ), obj, mem_ptr, L ); + const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*); + typedef std::array data_t; + int upvalue = 1; + data_t data = { { } }; + fx_t* fxptr; + for (std::size_t i = 0, d = 0; d < sizeof(fx_t*); ++i, d += sizeof(void*)) { + data[ i ] = lua_touserdata(L, lua_upvalueindex(upvalue++)); + } + fxptr = reinterpret_cast(static_cast(data.data())); + fx_t& mem_ptr = *fxptr; + void* objectdata = lua_touserdata(L, lua_upvalueindex(upvalue++)); + T& obj = *static_cast(objectdata); + int r = typed_call(tuple_types(), typename fx_traits::args_type(), obj, mem_ptr, L); return r; } diff --git a/sol/stack.hpp b/sol/stack.hpp index dc8cd811..bda81815 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -45,7 +45,7 @@ inline T get_unsigned(lua_State* L, std::true_type, int index = -1) { template inline T get_unsigned(lua_State* L, std::false_type, int index = -1) { - return static_cast( lua_tointeger(L, index) ); + return static_cast(lua_tointeger(L, index)); } template @@ -68,7 +68,7 @@ inline T get_helper(lua_State* L, std::true_type, int index = -1) { template inline T get_nil(lua_State* L, std::true_type, int index = -1) { if (lua_isnil(L, index) == 0) - throw sol::sol_error("not nil"); + throw sol::sol_error("not nil"); return nil_t{}; } @@ -196,19 +196,19 @@ inline void push(lua_State* L, const std::array& data) { } } -template -inline int push_user( lua_State* L, T& item ) { - typedef typename std::decay::type TValue; - const static std::size_t itemsize = sizeof( TValue ); - const static std::size_t voidsize = sizeof( void* ); - const static std::size_t voidsizem1 = voidsize - 1; - const static std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize; - typedef std::array data_t; +template +inline int push_user(lua_State* L, T& item) { + typedef typename std::decay::type TValue; + const static std::size_t itemsize = sizeof(TValue); + const static std::size_t voidsize = sizeof(void*); + const static std::size_t voidsizem1 = voidsize - 1; + const static std::size_t data_t_count = (sizeof(TValue) + voidsizem1) / voidsize; + typedef std::array data_t; - data_t data{{}}; - std::memcpy( std::addressof( data[ 0 ] ), std::addressof( item ), itemsize ); - push( L, data ); - return data_t_count; + data_t data{{}}; + std::memcpy(std::addressof(data[ 0 ]), std::addressof(item), itemsize); + push(L, data); + return data_t_count; } namespace detail { diff --git a/sol/state.hpp b/sol/state.hpp index ebd4ced7..4f2f34ea 100644 --- a/sol/state.hpp +++ b/sol/state.hpp @@ -115,14 +115,22 @@ public: } } + void eval(const std::string& code) { + script(code); + } + void script(const std::string& code) { if(luaL_dostring(L.get(), code.c_str())) { lua_error(L.get()); } } - void open_file(const std::string& filename) { - if(luaL_dofile(L.get(), filename.c_str())) { + void eval_file(const std::string& filename) { + script_file(filename); + } + + void script_file(const std::string& filename) { + if (luaL_dofile(L.get(), filename.c_str())) { lua_error(L.get()); } } diff --git a/sol/table.hpp b/sol/table.hpp index bcf635bb..14120adc 100644 --- a/sol/table.hpp +++ b/sol/table.hpp @@ -170,7 +170,7 @@ private: push(); - int upvalues = stack::push_user( state( ), target ); + int upvalues = stack::push_user(state(), target); luaL_setfuncs(state(), funcreg, upvalues); lua_pop(state(), 1); @@ -199,7 +199,7 @@ private: lua_settable(state(), -3); } - push(); + push(); stack::push_user(state(), userdata, metatablename); luaL_setfuncs(state(), funcreg, 1); From bcf4b9b08fc1fc05afa371babba3ba5f795da248 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 11:56:34 -0500 Subject: [PATCH 06/15] Have I mentioned I hate GCC? I hate GCC. --- .gitignore | 1 + sol.scratch.cpp | 2 +- sol/functional.hpp | 4 ++-- sol/lua_function.hpp | 6 +++--- sol/stack.hpp | 14 +++++++++----- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index bfbe70a6..2ea95f2b 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ x64/ liblua.a sol/include/ .ninja* +include/ diff --git a/sol.scratch.cpp b/sol.scratch.cpp index fb968850..2ee0c5ae 100644 --- a/sol.scratch.cpp +++ b/sol.scratch.cpp @@ -50,7 +50,7 @@ TEST_CASE("simple/get", "Tests if the get function works properly.") { REQUIRE(a == 9.0); lua.script("b = nil"); - REQUIRE_NOTHROW(auto b = lua.get("b")); + REQUIRE_NOTHROW(lua.get("b")); lua.script("d = 'hello'"); auto d = lua.get("d"); diff --git a/sol/functional.hpp b/sol/functional.hpp index 653864db..0ede1e5a 100644 --- a/sol/functional.hpp +++ b/sol/functional.hpp @@ -19,11 +19,11 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#include "tuple.hpp" - #ifndef SOL_FUNCTIONAL_HPP #define SOL_FUNCTIONAL_HPP +#include "tuple.hpp" + namespace sol { namespace detail { diff --git a/sol/lua_function.hpp b/sol/lua_function.hpp index e73f818e..d98e553b 100644 --- a/sol/lua_function.hpp +++ b/sol/lua_function.hpp @@ -80,7 +80,7 @@ struct static_lua_func { static int call(lua_State* L) { int upvalue = 1; fx_t* fx; - detail::get_upvalue(L, fx, upvalue); + detail::get_upvalue(L, fx, upvalue); int r = typed_call(tuple_types(), typename fx_traits::args_type(), fx, L); return r; } @@ -106,7 +106,7 @@ struct static_object_lua_func { static int typed_call(types, types, T& item, fx_t& ifx, lua_State* L) { auto fx = [ &item, &ifx ] (Args&&... args) -> TR { return (item.*ifx)(std::forward(args)...); - }; + }; auto r = stack::pop_call(L, fx, types()); stack::push(L, std::move(r)); return 1; @@ -121,7 +121,7 @@ struct static_object_lua_func { } static int call(lua_State* L) { - const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*); + const static std::size_t data_t_count = (sizeof(fx_t)+(sizeof(void*)-1)) / sizeof(void*); typedef std::array data_t; int upvalue = 1; data_t data = { { } }; diff --git a/sol/stack.hpp b/sol/stack.hpp index bda81815..ce8be78e 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -60,11 +60,6 @@ inline T get_arithmetic(lua_State* L, std::true_type, int index = -1) { return get_unsigned(L, std::is_unsigned{}, index); } -template -inline T get_helper(lua_State* L, std::true_type, int index = -1) { - return get_nil(L, std::is_same(), index); -} - template inline T get_nil(lua_State* L, std::true_type, int index = -1) { if (lua_isnil(L, index) == 0) @@ -78,6 +73,11 @@ inline T get_nil(lua_State* L, std::false_type, int index = -1) { return T(L, index); } +template +inline T get_helper(lua_State* L, std::true_type, int index = -1) { + return get_nil(L, std::is_same(), index); +} + template inline T get_helper(lua_State* L, std::false_type, int index = -1) { // T is a fundamental type @@ -222,6 +222,10 @@ template auto ltr_pop(lua_State*, F&& f, types<>, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { return f(std::forward(vs)...); } +template +auto ltr_pop(lua_State*, F&& f, types, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { + return f(std::forward(vs)...); +} template auto ltr_pop(lua_State* L, F&& f, types, Vs&&... vs) -> decltype(ltr_pop(L, std::forward(f), types<>(), std::forward(vs)..., pop(L))) { return ltr_pop(L, std::forward(f), types<>(), std::forward(vs)..., pop(L)); From 459bbcaba0c6d802e2153aca13f6849528c9e735 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 12:42:00 -0500 Subject: [PATCH 07/15] GCC is lame. But at least it's building now. Fixed up the build.ninja and made all tests pass (exceptions weren't being thrown because of `lua_pcall`: use `lua_call` to let exceptions propogate naturally). --- build.ninja | 2 +- sol.scratch.cpp | 10 ++++++---- sol/function.hpp | 14 +++++++++----- sol/stack.hpp | 6 +----- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/build.ninja b/build.ninja index c6a0c4a9..8693c9ae 100644 --- a/build.ninja +++ b/build.ninja @@ -6,7 +6,7 @@ objdir = obj cxx = g++ cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG incflags = -I"." -I"./include" -I"." -I"./lua-5.2.2/src/" -I"./Catch/include/" -linkflags = -static liblua.a -L"./lib" +linkflags = -static -L"./lib" -llua rule compile command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags diff --git a/sol.scratch.cpp b/sol.scratch.cpp index 2ee0c5ae..efde5c1f 100644 --- a/sol.scratch.cpp +++ b/sol.scratch.cpp @@ -97,8 +97,10 @@ TEST_CASE("simple/callWithParameters", "Lua function is called with a few parame REQUIRE_NOTHROW(lua.script("function my_add(i, j, k) return i + j + k end")); auto f = lua.get("my_add"); - REQUIRE_NOTHROW(f.call(1, 2, 3)); - REQUIRE_THROWS(f.call(1, 2, "arf")); + int a; + REQUIRE_NOTHROW(a = f.call(1, 2, 3)); + REQUIRE(a == 6); + REQUIRE_THROWS(a = f.call(1, 2, "arf")); } TEST_CASE("simple/callCppFunction", "C++ function is called from lua") { @@ -164,7 +166,7 @@ TEST_CASE("negative/basicError", "Check if error handling works correctly") { std::cout << "stateless lambda()" << std::endl; return "test"; } - ); + ); run_script(lua); lua.get("os").set_function("fun", &free_function); @@ -183,7 +185,7 @@ TEST_CASE("negative/basicError", "Check if error handling works correctly") { std::cout << "stateless lambda()" << std::endl; return "test"; } - ); + ); run_script(lua); // r-value, cannot optomize diff --git a/sol/function.hpp b/sol/function.hpp index edf44337..49319308 100644 --- a/sol/function.hpp +++ b/sol/function.hpp @@ -29,24 +29,28 @@ namespace sol { class function : virtual public reference { private: + void luacall (std::size_t argcount, std::size_t resultcount) { + lua_call(state(), static_cast(argcount), static_cast(resultcount)); + } + template std::tuple invoke(types, std::size_t n) { - lua_pcall(state(), static_cast(n), sizeof...(Ret), 0); - return stack::pop_call(state(), std::make_tuple, types()); + luacall(n, sizeof...(Ret)); + return stack::pop_call(state(), std::make_tuple, types()); } template Ret invoke(types, std::size_t n) { - lua_pcall(state(), static_cast(n), 1, 0); + luacall(n, 1); return stack::pop(state()); } void invoke(types, std::size_t n) { - lua_pcall(state(), static_cast(n), 0, 0); + luacall(n, 0); } void invoke(types<>, std::size_t n) { - lua_pcall(state(), static_cast(n), 0, 0); + luacall(n, 0); } public: diff --git a/sol/stack.hpp b/sol/stack.hpp index ce8be78e..b301072a 100644 --- a/sol/stack.hpp +++ b/sol/stack.hpp @@ -222,16 +222,12 @@ template auto ltr_pop(lua_State*, F&& f, types<>, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { return f(std::forward(vs)...); } -template -auto ltr_pop(lua_State*, F&& f, types, Vs&&... vs) -> decltype(f(std::forward(vs)...)) { - return f(std::forward(vs)...); -} template auto ltr_pop(lua_State* L, F&& f, types, Vs&&... vs) -> decltype(ltr_pop(L, std::forward(f), types<>(), std::forward(vs)..., pop(L))) { return ltr_pop(L, std::forward(f), types<>(), std::forward(vs)..., pop(L)); } template -auto ltr_pop(lua_State* L, F&& f, types, Vs&&... vs) -> decltype(ltr_pop(L, std::forward(f), types(), std::forward(vs)..., pop(L))) { +auto ltr_pop(lua_State* L, F&& f, types, Vs&&... vs) -> decltype(f(std::forward(vs)..., std::declval(), std::declval()...)) { return ltr_pop(L, std::forward(f), types(), std::forward(vs)..., pop(L)); } } // detail From e6a9688b80a05b4c065da44a3ced212ca71bd9e2 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 12:51:10 -0500 Subject: [PATCH 08/15] If this works, Ninja is stupid. --- build.ninja | 54 ++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/build.ninja b/build.ninja index 8693c9ae..66d92715 100644 --- a/build.ninja +++ b/build.ninja @@ -1,27 +1,27 @@ -# This file has been generated by shinobi version 0.9.5 - -ninja_required_version = 1.3 -builddir = bin -objdir = obj -cxx = g++ -cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG -incflags = -I"." -I"./include" -I"." -I"./lua-5.2.2/src/" -I"./Catch/include/" -linkflags = -static -L"./lib" -llua - -rule compile - command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags - deps = gcc - depfile = $out.d - description = Compiling $in - -rule link - command = $cxx $in -o $out $linkflags - description = Creating $out - -build $objdir/sol.scratch.o: compile sol.scratch.cpp - -build $builddir/sol.scratch: link $objdir/sol.scratch.o - -build install: phony $builddir/sol.scratch - -default install +# This file has been generated by shinobi version 0.9.5 + +ninja_required_version = 1.3 +builddir = bin +objdir = obj +cxx = g++ +cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG +incflags = -I"." -I"./include" -I"." -I"./lua-5.2.2/src/" -I"./Catch/include/" +linkflags = -static -L"./lib" -llua + +rule compile + command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags + deps = gcc + depfile = $out.d + description = Compiling $in + +rule link + command = $cxx $in -o $out $linkflags + description = Creating $out + +build $objdir/sol.scratch.o: compile sol.scratch.cpp + +build $builddir/sol.scratch: link $objdir/sol.scratch.o + +build install: phony $builddir/sol.scratch + +default install From b77fd29f374a0cdbfb4939ea7804eb066bb19d5a Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 13:14:34 -0500 Subject: [PATCH 09/15] ~Installed~ --- build.ninja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ninja b/build.ninja index 66d92715..8b1c38cf 100644 --- a/build.ninja +++ b/build.ninja @@ -5,7 +5,7 @@ builddir = bin objdir = obj cxx = g++ cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG -incflags = -I"." -I"./include" -I"." -I"./lua-5.2.2/src/" -I"./Catch/include/" +incflags = -I"." -I"./include" -I"." =I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/" linkflags = -static -L"./lib" -llua rule compile From 029bd91e23d87268648869ff2b004b494e34b3fb Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 13:17:14 -0500 Subject: [PATCH 10/15] Weeee, = instead of -! --- build.ninja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ninja b/build.ninja index 8b1c38cf..5d707dc2 100644 --- a/build.ninja +++ b/build.ninja @@ -5,7 +5,7 @@ builddir = bin objdir = obj cxx = g++ cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG -incflags = -I"." -I"./include" -I"." =I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/" +incflags = -I"." -I"./include" -I"." -I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/" linkflags = -static -L"./lib" -llua rule compile From 9204a019babc9efbd179bfeaeec264ca480ea34d Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 13:22:05 -0500 Subject: [PATCH 11/15] Checking once more if we need additional library paths... --- build.ninja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ninja b/build.ninja index 5d707dc2..7d3b5df5 100644 --- a/build.ninja +++ b/build.ninja @@ -6,7 +6,7 @@ objdir = obj cxx = g++ cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG incflags = -I"." -I"./include" -I"." -I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/" -linkflags = -static -L"./lib" -llua +linkflags = -static -L"./lib" -L"/usr/lib/lua5.2" -llua rule compile command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags From e9d90d617c9798b32dd53a6017a73f0ac09aa3ab Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 13:26:54 -0500 Subject: [PATCH 12/15] Well, -llua5.2. At least it's more explicit. --- build.ninja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ninja b/build.ninja index 7d3b5df5..9ba43068 100644 --- a/build.ninja +++ b/build.ninja @@ -6,7 +6,7 @@ objdir = obj cxx = g++ cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG incflags = -I"." -I"./include" -I"." -I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/" -linkflags = -static -L"./lib" -L"/usr/lib/lua5.2" -llua +linkflags = -static -L"./lib" -llua5.2 rule compile command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags From 0da6ff4690989b3f52c1333dae1e2f0fccae23a5 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 18:14:12 -0500 Subject: [PATCH 13/15] Test cases for tables and the opening of libraries. --- sol.scratch.cpp | 64 +++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/sol.scratch.cpp b/sol.scratch.cpp index efde5c1f..3600df44 100644 --- a/sol.scratch.cpp +++ b/sol.scratch.cpp @@ -21,11 +21,6 @@ int plop_xyz(int x, int y, std::string z) { return 11; } -void run_script(sol::state& lua) { - lua.script("assert(os.fun() == \"test\")\n" - "assert(os.name == \"windows\")"); -} - TEST_CASE("simple/set_global", "Check if the set_global works properly.") { sol::state lua; @@ -81,17 +76,6 @@ TEST_CASE("simple/if", "") { REQUIRE(f == 0.1); } -TEST_CASE("simple/evalStream", "The VM evaluates a stream's contents using a reader") { - sol::state lua; - - std::stringstream sscript; - int g = 9; - sscript << "g = " << g << ";"; - - REQUIRE_NOTHROW(lua.script(sscript.str())); - REQUIRE(lua.get("g") == 9.0); -} - TEST_CASE("simple/callWithParameters", "Lua function is called with a few parameters from C++") { sol::state lua; @@ -157,27 +141,41 @@ TEST_CASE("negative/basicError", "Check if error handling works correctly") { REQUIRE_THROWS(lua.script("nil[5]")); } -/* - lua.get("os").set("name", "windows"); +TEST_CASE("libraries", "Check if we can open libraries through sol") { + sol::state lua; + REQUIRE_NOTHROW(lua.open_libraries(sol::lib::base, sol::lib::os)); +} + +TEST_CASE("tables/variables", "Check if tables and variables work as intended") { + sol::state lua; + lua.open_libraries(sol::lib::base, sol::lib::os); + lua.get("os").set("name", "windows"); + REQUIRE_NOTHROW(lua.script("assert(os.name == \"windows\")")); +} + +TEST_CASE("tables/functions_variables", "Check if tables and function calls work as intended") { + sol::state lua; + lua.open_libraries(sol::lib::base, sol::lib::os); + auto run_script = [ ] (sol::state& lua) -> void { + lua.script("assert(os.fun() == \"test\")"); + }; - SECTION("") lua.get("os").set_function("fun", [ ] () { - std::cout << "stateless lambda()" << std::endl; - return "test"; - } - ); - run_script(lua); + std::cout << "stateless lambda()" << std::endl; + return "test"; + } + ); + REQUIRE_NOTHROW(run_script(lua)); lua.get("os").set_function("fun", &free_function); - run_script(lua); + REQUIRE_NOTHROW(run_script(lua)); // l-value, can optomize auto lval = object(); lua.get("os").set_function("fun", &object::operator(), lval); - run_script(lua); + REQUIRE_NOTHROW((lua)); - // Tests will begin failing here // stateful lambda: non-convertible, unoptomizable int breakit = 50; lua.get("os").set_function("fun", @@ -185,17 +183,15 @@ TEST_CASE("negative/basicError", "Check if error handling works correctly") { std::cout << "stateless lambda()" << std::endl; return "test"; } - ); - run_script(lua); + ); + REQUIRE_NOTHROW(run_script(lua)); // r-value, cannot optomize lua.get("os").set_function("fun", &object::operator(), object()); - run_script(lua); + REQUIRE_NOTHROW(run_script(lua)); // r-value, cannot optomize auto rval = object(); lua.get("os").set_function("fun", &object::operator(), std::move(rval)); - run_script(lua); - -} -*/ + REQUIRE_NOTHROW(run_script(lua)); +} \ No newline at end of file From 2b4f9cc24cde4d15817bcbadcbec7a305d776198 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 18:16:52 -0500 Subject: [PATCH 14/15] Meh, who needs "eval". It's technically right, but I think evaluate might be for shorter lines and stuff... who knows. --- sol/state.hpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/sol/state.hpp b/sol/state.hpp index 4f2f34ea..a6888cb0 100644 --- a/sol/state.hpp +++ b/sol/state.hpp @@ -115,20 +115,12 @@ public: } } - void eval(const std::string& code) { - script(code); - } - void script(const std::string& code) { if(luaL_dostring(L.get(), code.c_str())) { lua_error(L.get()); } } - void eval_file(const std::string& filename) { - script_file(filename); - } - void script_file(const std::string& filename) { if (luaL_dofile(L.get(), filename.c_str())) { lua_error(L.get()); From a59320787f9505dba5325a3c0241323648b1e108 Mon Sep 17 00:00:00 2001 From: ThePhD Date: Wed, 11 Dec 2013 23:43:33 -0500 Subject: [PATCH 15/15] We apparently need to link in `dl` (`dladdr`) manually. --- build.ninja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ninja b/build.ninja index 9ba43068..e574064c 100644 --- a/build.ninja +++ b/build.ninja @@ -6,7 +6,7 @@ objdir = obj cxx = g++ cxxflags = -std=c++11 -pedantic -pedantic-errors -Wextra -Wall -O2 -DNDEBUG incflags = -I"." -I"./include" -I"." -I"/usr/include/lua5.2" -I"./lua-5.2.2/src/" -I"./Catch/include/" -linkflags = -static -L"./lib" -llua5.2 +linkflags = -static -L"./lib" -llua5.2 -ldl rule compile command = $cxx -MMD -MF $out.d $cxxflags -c $in -o $out $incflags