mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
fix compat loadfilex issues and investigate luajit completely
This commit is contained in:
parent
7aca8ac8cd
commit
b38a382b03
|
@ -20,8 +20,8 @@
|
||||||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
// This file was generated with a script.
|
// This file was generated with a script.
|
||||||
// Generated 2017-09-10 14:55:41.345191 UTC
|
// Generated 2017-09-10 16:07:52.509059 UTC
|
||||||
// This header was generated with sol v2.18.2 (revision ae07a5d)
|
// This header was generated with sol v2.18.2 (revision 7aca8ac)
|
||||||
// https://github.com/ThePhD/sol2
|
// https://github.com/ThePhD/sol2
|
||||||
|
|
||||||
#ifndef SOL_SINGLE_INCLUDE_HPP
|
#ifndef SOL_SINGLE_INCLUDE_HPP
|
||||||
|
@ -2320,8 +2320,12 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
|
||||||
static const char* compat53_f_parser_handler (lua_State *L, void *data, size_t *size) {
|
static const char* compat53_f_parser_handler (lua_State *L, void *data, size_t *size) {
|
||||||
(void)L; /* better fix for unused parameter warnings */
|
(void)L; /* better fix for unused parameter warnings */
|
||||||
struct compat53_f_parser_buffer *p = (struct compat53_f_parser_buffer*)data;
|
struct compat53_f_parser_buffer *p = (struct compat53_f_parser_buffer*)data;
|
||||||
|
if (feof(p->file) != 0) {
|
||||||
|
*size = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
size_t readcount = fread(p->buffer + p->start, sizeof(*p->buffer), sizeof(p->buffer), p->file);
|
size_t readcount = fread(p->buffer + p->start, sizeof(*p->buffer), sizeof(p->buffer), p->file);
|
||||||
if (ferror(p->file) != 0 || feof(p->file) != 0) {
|
if (ferror(p->file) != 0) {
|
||||||
*size = 0;
|
*size = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -2378,6 +2382,7 @@ COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char
|
||||||
struct compat53_f_parser_buffer fbuf;
|
struct compat53_f_parser_buffer fbuf;
|
||||||
fbuf.file = fp;
|
fbuf.file = fp;
|
||||||
fbuf.start = 1;
|
fbuf.start = 1;
|
||||||
|
fbuf.buffer[0] = (char)c;
|
||||||
status = lua_load(L, &compat53_f_parser_handler, &fbuf, filename);
|
status = lua_load(L, &compat53_f_parser_handler, &fbuf, filename);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return status;
|
return status;
|
||||||
|
@ -17215,7 +17220,7 @@ namespace sol {
|
||||||
if (loaded && loaded->valid())
|
if (loaded && loaded->valid())
|
||||||
return std::move(*loaded);
|
return std::move(*loaded);
|
||||||
action();
|
action();
|
||||||
auto sr = stack::get<stack_reference>(L);
|
stack_reference sr(L, -1);
|
||||||
if (create_global)
|
if (create_global)
|
||||||
set(key, sr);
|
set(key, sr);
|
||||||
ensure_package(key, sr);
|
ensure_package(key, sr);
|
||||||
|
@ -17337,11 +17342,17 @@ namespace sol {
|
||||||
}
|
}
|
||||||
|
|
||||||
object require_script(const std::string& key, const string_view& code, bool create_global = true, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
|
object require_script(const std::string& key, const string_view& code, bool create_global = true, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
|
||||||
return require_core(key, [this, &code, &chunkname, &mode]() {stack::script(L, code, chunkname, mode); }, create_global);
|
auto action = [this, &code, &chunkname, &mode]() {
|
||||||
|
stack::script(L, code, chunkname, mode);
|
||||||
|
};
|
||||||
|
return require_core(key, action, create_global);
|
||||||
}
|
}
|
||||||
|
|
||||||
object require_file(const std::string& key, const std::string& filename, bool create_global = true, load_mode mode = load_mode::any) {
|
object require_file(const std::string& key, const std::string& filename, bool create_global = true, load_mode mode = load_mode::any) {
|
||||||
return require_core(key, [this, &filename, &mode]() {stack::script_file(L, filename, mode); }, create_global);
|
auto action = [this, &filename, &mode]() {
|
||||||
|
stack::script_file(L, filename, mode);
|
||||||
|
};
|
||||||
|
return require_core(key, action, create_global);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
|
|
|
@ -421,8 +421,12 @@ COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
|
||||||
static const char* compat53_f_parser_handler (lua_State *L, void *data, size_t *size) {
|
static const char* compat53_f_parser_handler (lua_State *L, void *data, size_t *size) {
|
||||||
(void)L; /* better fix for unused parameter warnings */
|
(void)L; /* better fix for unused parameter warnings */
|
||||||
struct compat53_f_parser_buffer *p = (struct compat53_f_parser_buffer*)data;
|
struct compat53_f_parser_buffer *p = (struct compat53_f_parser_buffer*)data;
|
||||||
|
if (feof(p->file) != 0) {
|
||||||
|
*size = 0;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
size_t readcount = fread(p->buffer + p->start, sizeof(*p->buffer), sizeof(p->buffer), p->file);
|
size_t readcount = fread(p->buffer + p->start, sizeof(*p->buffer), sizeof(p->buffer), p->file);
|
||||||
if (ferror(p->file) != 0 || feof(p->file) != 0) {
|
if (ferror(p->file) != 0) {
|
||||||
*size = 0;
|
*size = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -481,6 +485,7 @@ COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char
|
||||||
struct compat53_f_parser_buffer fbuf;
|
struct compat53_f_parser_buffer fbuf;
|
||||||
fbuf.file = fp;
|
fbuf.file = fp;
|
||||||
fbuf.start = 1;
|
fbuf.start = 1;
|
||||||
|
fbuf.buffer[0] = (char)c;
|
||||||
status = lua_load(L, &compat53_f_parser_handler, &fbuf, filename);
|
status = lua_load(L, &compat53_f_parser_handler, &fbuf, filename);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -146,7 +146,7 @@ namespace sol {
|
||||||
if (loaded && loaded->valid())
|
if (loaded && loaded->valid())
|
||||||
return std::move(*loaded);
|
return std::move(*loaded);
|
||||||
action();
|
action();
|
||||||
auto sr = stack::get<stack_reference>(L);
|
stack_reference sr(L, -1);
|
||||||
if (create_global)
|
if (create_global)
|
||||||
set(key, sr);
|
set(key, sr);
|
||||||
ensure_package(key, sr);
|
ensure_package(key, sr);
|
||||||
|
@ -268,11 +268,17 @@ namespace sol {
|
||||||
}
|
}
|
||||||
|
|
||||||
object require_script(const std::string& key, const string_view& code, bool create_global = true, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
|
object require_script(const std::string& key, const string_view& code, bool create_global = true, const std::string& chunkname = detail::default_chunk_name(), load_mode mode = load_mode::any) {
|
||||||
return require_core(key, [this, &code, &chunkname, &mode]() {stack::script(L, code, chunkname, mode); }, create_global);
|
auto action = [this, &code, &chunkname, &mode]() {
|
||||||
|
stack::script(L, code, chunkname, mode);
|
||||||
|
};
|
||||||
|
return require_core(key, action, create_global);
|
||||||
}
|
}
|
||||||
|
|
||||||
object require_file(const std::string& key, const std::string& filename, bool create_global = true, load_mode mode = load_mode::any) {
|
object require_file(const std::string& key, const std::string& filename, bool create_global = true, load_mode mode = load_mode::any) {
|
||||||
return require_core(key, [this, &filename, &mode]() {stack::script_file(L, filename, mode); }, create_global);
|
auto action = [this, &filename, &mode]() {
|
||||||
|
stack::script_file(L, filename, mode);
|
||||||
|
};
|
||||||
|
return require_core(key, action, create_global);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename E>
|
template <typename E>
|
||||||
|
|
|
@ -40,12 +40,24 @@ struct write_file_attempt_object {
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_CASE("state/require_file", "opening files as 'requires'") {
|
TEST_CASE("state/require_file", "opening files as 'requires'") {
|
||||||
static const char FILE_NAME[] = "./tmp_thingy.lua";
|
static const char file_require_file[] = "./tmp_thingy.lua";
|
||||||
static const char FILE_NAME_USER[] = "./tmp_thingy_user.lua";
|
static const char file_require_file_user[] = "./tmp_thingy_user.lua";
|
||||||
|
static const char require_file_code[] = "return { modfunc = function () return 221 end }";
|
||||||
|
static const char require_file_user_code[] = "return { modfunc = function () return foo.new(221) end }";
|
||||||
|
static std::atomic<int> finished(0);
|
||||||
|
static std::once_flag flag_file = {}, flag_file_user = {};
|
||||||
|
std::call_once(flag_file, write_file_attempt_object(), file_require_file, require_file_code);
|
||||||
|
std::call_once(flag_file_user, write_file_attempt_object(), file_require_file_user, require_file_user_code);
|
||||||
|
|
||||||
SECTION("with usertypes") {
|
auto clean_files = []() {
|
||||||
write_file_attempt(FILE_NAME_USER, "return { modfunc = function () return foo.new(221) end }");
|
if (finished.fetch_add(1) < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::remove(file_require_file);
|
||||||
|
std::remove(file_require_file_user);
|
||||||
|
};
|
||||||
|
|
||||||
|
SECTION("with usertypes") {
|
||||||
struct foo {
|
struct foo {
|
||||||
foo(int bar) : bar(bar) {}
|
foo(int bar) : bar(bar) {}
|
||||||
|
|
||||||
|
@ -60,7 +72,7 @@ TEST_CASE("state/require_file", "opening files as 'requires'") {
|
||||||
"bar", &foo::bar
|
"bar", &foo::bar
|
||||||
);
|
);
|
||||||
|
|
||||||
const sol::table thingy1 = lua.require_file("thingy", FILE_NAME_USER);
|
const sol::table thingy1 = lua.require_file("thingy", file_require_file_user);
|
||||||
|
|
||||||
REQUIRE(thingy1.valid());
|
REQUIRE(thingy1.valid());
|
||||||
|
|
||||||
|
@ -69,16 +81,15 @@ TEST_CASE("state/require_file", "opening files as 'requires'") {
|
||||||
int val1 = foo_v.bar;
|
int val1 = foo_v.bar;
|
||||||
|
|
||||||
REQUIRE(val1 == 221);
|
REQUIRE(val1 == 221);
|
||||||
|
clean_files();
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("simple") {
|
SECTION("simple") {
|
||||||
write_file_attempt(FILE_NAME, "return { modfunc = function () return 221 end }");
|
|
||||||
|
|
||||||
sol::state lua;
|
sol::state lua;
|
||||||
lua.open_libraries(sol::lib::base);
|
lua.open_libraries(sol::lib::base);
|
||||||
|
|
||||||
const sol::table thingy1 = lua.require_file("thingy", FILE_NAME);
|
const sol::table thingy1 = lua.require_file("thingy", file_require_file);
|
||||||
const sol::table thingy2 = lua.require_file("thingy", FILE_NAME);
|
const sol::table thingy2 = lua.require_file("thingy", file_require_file);
|
||||||
|
|
||||||
REQUIRE(thingy1.valid());
|
REQUIRE(thingy1.valid());
|
||||||
REQUIRE(thingy2.valid());
|
REQUIRE(thingy2.valid());
|
||||||
|
@ -90,9 +101,8 @@ TEST_CASE("state/require_file", "opening files as 'requires'") {
|
||||||
REQUIRE(val2 == 221);
|
REQUIRE(val2 == 221);
|
||||||
// must have loaded the same table
|
// must have loaded the same table
|
||||||
REQUIRE((thingy1 == thingy2));
|
REQUIRE((thingy1 == thingy2));
|
||||||
|
clean_files();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::remove(FILE_NAME);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("state/require_script", "opening strings as 'requires' clauses") {
|
TEST_CASE("state/require_script", "opening strings as 'requires' clauses") {
|
||||||
|
@ -337,7 +347,7 @@ TEST_CASE("state/script, do, and load", "test success and failure cases for load
|
||||||
std::call_once(flag_file_g, write_file_attempt_object(), file_good, good);
|
std::call_once(flag_file_g, write_file_attempt_object(), file_good, good);
|
||||||
|
|
||||||
auto clean_files = []() {
|
auto clean_files = []() {
|
||||||
if (finished.fetch_add(1) != 11) {
|
if (finished.fetch_add(1) < 10) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::remove(file_bad_syntax);
|
std::remove(file_bad_syntax);
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
return { modfunc = function () return foo.new(221) end }
|
|
Loading…
Reference in New Issue
Block a user