diff --git a/bootstrap.py b/bootstrap.py index f2202a67..0eb0188d 100755 --- a/bootstrap.py +++ b/bootstrap.py @@ -42,6 +42,7 @@ parser.add_argument('--cxx', metavar='', help='compiler name to use (d parser.add_argument('--cxx-flags', help='additional flags passed to the compiler', default='') parser.add_argument('--ci', action='store_true', help=argparse.SUPPRESS) parser.add_argument('--testing', action='store_true', help=argparse.SUPPRESS) +parser.add_argument('--lua-version', help='Lua version, e.g. lua53', default='lua53') parser.add_argument('--lua-lib', help='lua library name (without the lib on *nix).', default='lua') parser.add_argument('--lua-dir', metavar='', help='directory lua is in with include and lib subdirectories') parser.add_argument('--install-dir', metavar='', help='directory to install the headers to', default=install_dir); @@ -82,7 +83,7 @@ if args.lua_dir: ldflags.extend(library_includes([os.path.join(args.lua_dir, 'lib')])) if 'linux' in sys.platform: - lua_version = os.environ.get('LUA_VERSION', 'lua53') + lua_version = os.environ.get('LUA_VERSION', args.lua_version) if re.match(r'lua5[1-3]', lua_version): # Using normal lua lua_lib = lua_version[:-1] + '.' + lua_version[-1] @@ -101,7 +102,7 @@ if 'linux' in sys.platform: ldflags.extend(libraries([lua_lib])) elif 'darwin' in sys.platform: # OSX - lua_version = os.environ.get('LUA_VERSION', 'lua53') + lua_version = os.environ.get('LUA_VERSION', args.lua_version) if re.match(r'lua5[1-3]', lua_version): # Using normal lua lua_incl = lua_version[:-1] + '.' + lua_version[-1] diff --git a/tests.cpp b/tests.cpp index 552636ce..8bf4bbdd 100644 --- a/tests.cpp +++ b/tests.cpp @@ -3,10 +3,13 @@ #include #include -#include + +#include +#include #include #include -#include +#include + #include "test_stack_guard.hpp" bool func_opt_ret_bool(sol::optional i) { @@ -316,6 +319,64 @@ TEST_CASE("object/conversions", "make sure all basic reference types can be made REQUIRE(omn.get_type() == sol::type::nil); } +TEST_CASE("state/require_file", "opening files as 'requires'") { + static const char FILE_NAME[] = "./tmp_thingy.lua"; + + std::fstream file(FILE_NAME, std::ios::out); + + sol::state lua; + lua.open_libraries(sol::lib::base); + + SECTION("with usertypes") + { + struct foo { + foo(int bar) : bar(bar) {} + + const int bar; + }; + + lua.new_usertype("foo", + sol::constructors>{}, + "bar", &foo::bar + ); + + file << "return { modfunc = function () return foo.new(221) end }" << std::endl; + file.close(); + + const sol::table thingy1 = lua.require_file("thingy", FILE_NAME); + + CHECK(thingy1.valid()); + + const foo foo_v = thingy1["modfunc"](); + + int val1 = foo_v.bar; + + CHECK(val1 == 221); + } + + SECTION("simple") + { + file << "return { modfunc = function () return 221 end }" << std::endl; + file.close(); + + const sol::table thingy1 = lua.require_file("thingy", FILE_NAME); + const sol::table thingy2 = lua.require_file("thingy", FILE_NAME); + + CHECK(thingy1.valid()); + CHECK(thingy2.valid()); + + int val1 = thingy1["modfunc"](); + int val2 = thingy2["modfunc"](); + + CHECK(val1 == 221); + CHECK(val2 == 221); + // must have loaded the same table + CHECK(thingy1 == thingy2); + } + + std::remove(FILE_NAME); +} + TEST_CASE("state/require_script", "opening strings as 'requires' clauses") { std::string code = "return { modfunc = function () return 221 end }";