1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-15 17:47:09 +00:00

Add a luaL_loadfile wrapper to lua::state

This commit is contained in:
Pavel Labath 2010-09-12 14:53:06 +02:00
parent 55282b64d8
commit c5e45008df
2 changed files with 33 additions and 0 deletions

View File

@ -351,6 +351,23 @@ namespace lua {
return safe_compare(&safe_compare_trampoline<&lua_lessthan>, index1, index2);
}
void state::loadfile(const char *filename)
throw(lua::syntax_error, lua::file_error, std::bad_alloc)
{
switch(luaL_loadfile(cobj.get(), filename)) {
case 0:
return;
case LUA_ERRSYNTAX:
throw lua::syntax_error(this);
case LUA_ERRFILE:
throw lua::file_error(this);
case LUA_ERRMEM:
throw std::bad_alloc();
default:
assert(0);
}
}
void state::loadstring(const char *s) throw(lua::syntax_error, std::bad_alloc)
{
switch(luaL_loadstring(cobj.get(), s)) {

View File

@ -124,6 +124,21 @@ namespace lua {
{}
};
// loadfile() encountered an error while opening/reading the file
class file_error: public lua::exception {
file_error(const file_error &) = delete;
const file_error& operator=(const file_error &) = delete;
public:
file_error(state *L)
: lua::exception(L)
{}
file_error(file_error &&other)
: lua::exception(std::move(other))
{}
};
// double fault, lua encountered an error while running the error handler function
class errfunc_error: public lua::exception {
errfunc_error(const errfunc_error &) = delete;
@ -259,6 +274,7 @@ namespace lua {
void gettable(int index);
void getglobal(const char *name) { getfield(GLOBALSINDEX, name); }
bool lessthan(int index1, int index2);
void loadfile(const char *filename) throw(lua::syntax_error, lua::file_error, std::bad_alloc);
void loadstring(const char *s) throw(lua::syntax_error, std::bad_alloc);
bool next(int index);
// register is a reserved word :/