diff options
| author | Alexander Pickering <alex@cogarr.net> | 2018-09-10 23:11:08 -0400 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2018-09-10 23:11:08 -0400 |
| commit | c38d5eca7091fc7f0206ed0c746622022b2ae508 (patch) | |
| tree | 8c01d4a941b4152675354b8b7a46c0906e9fb40c /src/client/lua_api/io | |
| parent | b3c0d2ead1f384b35615be562c5f06804e8990cb (diff) | |
| download | brokengine-c38d5eca7091fc7f0206ed0c746622022b2ae508.tar.gz brokengine-c38d5eca7091fc7f0206ed0c746622022b2ae508.tar.bz2 brokengine-c38d5eca7091fc7f0206ed0c746622022b2ae508.zip | |
Added documentation
Also added treeview guielemnt
Also added ifilesystem guielement
Also added io library
Diffstat (limited to 'src/client/lua_api/io')
| -rw-r--r-- | src/client/lua_api/io/ifilesystem.cpp | 106 | ||||
| -rw-r--r-- | src/client/lua_api/io/ifilesystem.hpp | 13 |
2 files changed, 119 insertions, 0 deletions
diff --git a/src/client/lua_api/io/ifilesystem.cpp b/src/client/lua_api/io/ifilesystem.cpp new file mode 100644 index 0000000..9d12b22 --- /dev/null +++ b/src/client/lua_api/io/ifilesystem.cpp @@ -0,0 +1,106 @@ +#include "ifilesystem.hpp" + +using namespace irr; +using namespace io; + +extern IrrlichtDevice* device; + + +// io.list() +int listfilesin(lua_State *L){ + IFileSystem *fs = device->getFileSystem(); + IFileList *fl = fs->createFileList(); + + unsigned long fc = fl->getFileCount(); + unsigned long i; + const char *path; + + lua_newtable(L); + for(i = 0; i < fc; i++){ + path = fl->getFileName(i).c_str(); + lua_pushnumber(L,i + 1); + lua_pushstring(L,path); + lua_settable(L,-3); + } + + return 1; +} + +// io.cd("directory") +int changedirectory(lua_State *L){ + IFileSystem *fs = device->getFileSystem(); + const char *dir = lua_tostring(L,-1); + lua_pop(L,1); + fs->changeWorkingDirectoryTo(path(dir)); + return 0; +} + +// io.log("text",level) +// io.log("text",level[,"hint"]) +int logmessage(lua_State *L){ + ILogger *log = device->getLogger(); + + const char *hint_c = ""; + const char *text_c = ""; + int nargs = lua_gettop(L); + if(nargs > 2){ + hint_c = lua_tostring(L,-1); + lua_pop(L,1);//"text",level + } + ELOG_LEVEL ll = (ELOG_LEVEL)lua_tointeger(L,-1);//"text",level + lua_pop(L,1);//"text" + text_c = lua_tostring(L,-1);//"text" + lua_pop(L,1);// + + log->log(text_c,hint_c,ll); + + return 0; +} + +//io.set_log_level(level) +int setloglevel(lua_State *L){ + ILogger *log = device->getLogger(); + + ELOG_LEVEL ll = (ELOG_LEVEL)lua_tointeger(L,-1); + log->setLogLevel(ll); + + return 0; +} + +static const luaL_reg ifilesystem_f[] = { + {"log", logmessage}, + {"set_log_level", setloglevel}, + {"list", listfilesin}, + {"cd", changedirectory}, + {0,0}, +}; + +static const luaL_reg ifilesystem_m[] = { + {0,0}, +}; + +void ifilesystem_register(lua_State* L){ + + luaL_newmetatable(L, "io.ifilesystem");//{m_iguibutton} + lua_newtable(L);//{m_iguibutton},{} + luaL_register(L,NULL,ifilesystem_m); + lua_setfield(L,-2,"__index");//{m_iguibutton} + + lua_pop(L,1); + printf("set io global\n"); + lua_getglobal(L,"io");//{io} + luaL_register(L,NULL,ifilesystem_f); + + lua_pushnumber(L,ELL_DEBUG); + lua_setfield(L,-2,"LOG_DEBUG"); + lua_pushnumber(L,ELL_INFORMATION); + lua_setfield(L,-2,"LOG_INFO"); + lua_pushnumber(L,ELL_WARNING); + lua_setfield(L,-2,"LOG_WARN"); + lua_pushnumber(L,ELL_ERROR); + lua_setfield(L,-2,"LOG_ERROR"); + lua_pushnumber(L,ELL_NONE); + lua_setfield(L,-2,"LOG_NONE"); + + lua_pop(L,1);// +} diff --git a/src/client/lua_api/io/ifilesystem.hpp b/src/client/lua_api/io/ifilesystem.hpp new file mode 100644 index 0000000..9a72120 --- /dev/null +++ b/src/client/lua_api/io/ifilesystem.hpp @@ -0,0 +1,13 @@ +#ifndef __H_ifilesystem +#define __H_ifilesystem + +extern "C" { + #include <lua.h> + #include <lauxlib.h> + #include <lualib.h> +} +#include <irrlicht.h> + +void ifilesystem_register(lua_State* L); + +#endif |
