28 #include <boost/scoped_ptr.hpp>
29 #include <boost/algorithm/string/predicate.hpp>
36 #define DBG_LUA LOG_STREAM(debug, log_scripting_lua)
37 #define LOG_LUA LOG_STREAM(info, log_scripting_lua)
38 #define WRN_LUA LOG_STREAM(warn, log_scripting_lua)
39 #define ERR_LUA LOG_STREAM(err, log_scripting_lua)
47 if(filename.size() < 2) {
50 if(filename[0] ==
'.' && filename[1] ==
'/') {
51 filename = currentdir + filename.substr(1);
53 if(
std::find(filename.begin(), filename.end(),
'\\') != filename.end()) {
58 size_t pos = filename.find(
"/./");
59 if(pos == std::string::npos) {
62 filename = filename.replace(pos, 2,
"");
66 size_t pos = filename.find(
"//");
67 if(pos == std::string::npos) {
70 filename = filename.replace(pos, 1,
"");
74 size_t pos = filename.find(
"/..");
75 if(pos == std::string::npos) {
78 size_t pos2 = filename.find_last_of(
'/', pos - 1);
79 if(pos == std::string::npos || pos2 >= pos) {
82 filename = filename.replace(pos2, pos- pos2 + 3,
"");
84 if(filename.find(
"..") != std::string::npos) {
128 fs->exceptions(std::ios_base::goodbit);
132 return luaL_error(L,
"Error when reading file");
135 fs->seekg(0, std::ios::beg);
137 return luaL_error(L,
"Error when reading file");
169 ERR_LUA <<
"read bytes from " << startpos <<
" to " << newpos <<
" in total " *size <<
" from steam\n";
170 ERR_LUA <<
"streamstate beeing "
172 <<
" endoffile:" << lfs->
pistream_->eof()
174 <<
" failbit:" << lfs->
pistream_->fail() <<
"\n";
184 LOG_LUA <<
"starting to read from " << fname <<
"\n";
222 catch(
const std::exception & ex)
#define luaL_addsize(B, s)
int intf_read_file(lua_State *L)
Checks if a file exists (not necessarily a Lua script).
int intf_have_file(lua_State *L)
Checks if a file exists (not necessarily a Lua script).
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
boost::scoped_ptr< std::istream > pistream_
lua_filestream(const std::string &fname)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUA_API int lua_getstack(lua_State *L, int level, lua_Debug *ar)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
GLdouble GLdouble GLdouble b
std::istream * istream_file(const std::string &fname, bool treat_failure_as_error=true)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUA_API void lua_remove(lua_State *L, int idx)
static int lua_loadfile(lua_State *L, const std::string &fname, const std::string &relativename)
static bool resolve_filename(std::string &filename, const std::string ¤tdir)
resolves filename where currentdir is the current directory, note that currentdir is no absolute dire...
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir=std::string())
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
LUA_API int lua_getinfo(lua_State *L, const char *what, lua_Debug *ar)
static const char * lua_read_data(lua_State *, void *data, size_t *size)
LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data, const char *chunkname, const char *mode)
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
Declarations for File-IO.
int load_file(lua_State *L)
Loads a Lua file and pushes the contents on the stack.
static lg::log_domain log_scripting_lua("scripting/lua")
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUA_API int lua_error(lua_State *L)
bool find(E event, F functor)
Tests whether an event handler is available.
Standard logging facilities (interface).
GLsizei const GLcharARB ** string
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
char buff_[LUAL_BUFFERSIZE]
#define luaL_checkstring(L, n)