From eb568846779722a9ec039ab3c78fbec401830bb6 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 13 Sep 2018 16:55:53 -0300 Subject: [PATCH] lua: use our base::open_file_raw to open files from io lib funcs --- src/app/script/engine.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/script/engine.cpp b/src/app/script/engine.cpp index 9fc86b8da..69b690930 100644 --- a/src/app/script/engine.cpp +++ b/src/app/script/engine.cpp @@ -14,6 +14,7 @@ #include "app/console.h" #include "app/script/luacpp.h" #include "base/chrono.h" +#include "base/file_handle.h" #include "base/fs.h" #include "base/fstream_path.h" #include "doc/anidir.h" @@ -109,6 +110,13 @@ void register_sprites_class(lua_State* L); void register_tag_class(lua_State* L); void register_tags_class(lua_State* L); +// We use our own fopen() that supports Unicode filename on Windows +extern "C" FILE* lua_user_fopen(const char* fname, + const char* mode) +{ + return base::open_file_raw(fname, mode); +} + Engine::Engine() : L(luaL_newstate()) , m_delegate(nullptr) @@ -122,12 +130,13 @@ Engine::Engine() luaL_requiref(L, LUA_GNAME, luaopen_base, 1); luaL_requiref(L, LUA_COLIBNAME, luaopen_coroutine, 1); luaL_requiref(L, LUA_TABLIBNAME, luaopen_table, 1); + luaL_requiref(L, LUA_IOLIBNAME, luaopen_io, 1); luaL_requiref(L, LUA_OSLIBNAME, luaopen_os, 1); luaL_requiref(L, LUA_STRLIBNAME, luaopen_string, 1); luaL_requiref(L, LUA_MATHLIBNAME, luaopen_math, 1); luaL_requiref(L, LUA_UTF8LIBNAME, luaopen_utf8, 1); luaL_requiref(L, LUA_DBLIBNAME, luaopen_debug, 1); - lua_pop(L, 8); + lua_pop(L, 9); // Overwrite Lua functions lua_register(L, "print", print);