fix reading binary file as string
This commit is contained in:
@@ -30,7 +30,7 @@ static int l_resolve(lua::State* L) {
|
|||||||
static int l_read(lua::State* L) {
|
static int l_read(lua::State* L) {
|
||||||
io::path path = lua::require_string(L, 1);
|
io::path path = lua::require_string(L, 1);
|
||||||
if (io::is_regular_file(path)) {
|
if (io::is_regular_file(path)) {
|
||||||
return lua::pushstring(L, io::read_string(path));
|
return lua::pushlstring(L, io::read_string(path));
|
||||||
}
|
}
|
||||||
throw std::runtime_error(
|
throw std::runtime_error(
|
||||||
"file does not exists " + util::quote(path.string())
|
"file does not exists " + util::quote(path.string())
|
||||||
|
|||||||
@@ -184,6 +184,11 @@ namespace lua {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline int pushlstring(lua::State* L, std::string_view view) {
|
||||||
|
lua_pushlstring(L, reinterpret_cast<const char*>(view.data()), view.size());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
inline int pushfstring(lua_State* L, const char* fmt, Args... args) {
|
inline int pushfstring(lua_State* L, const char* fmt, Args... args) {
|
||||||
lua_pushfstring(L, fmt, args...);
|
lua_pushfstring(L, fmt, args...);
|
||||||
|
|||||||
Reference in New Issue
Block a user