diff --git a/ag.cc b/ag.cc index d76c6bd..dd1ecd9 100644 --- a/ag.cc +++ b/ag.cc @@ -1,7 +1,10 @@ +#include "anaglym.h" #include "ag.h" -#include +#include "wfobj/WFObj.hh" #include +#include +#include using namespace std; namespace ag @@ -11,6 +14,7 @@ namespace ag static const luaL_Reg functions[] = { { "print", ag_print }, { "println", ag_println }, + { "loadModel", ag_loadModel }, { NULL, NULL } }; luaL_register(L, "ag", functions); @@ -75,7 +79,33 @@ namespace ag int ag_println(lua_State * L) { - ag_print(L); + int ret = ag_print(L); cout << endl; + return ret; + } + + int ag_loadModel(lua_State * L) + { + int argc = lua_gettop(L); + + if (argc == 1) + { + if (lua_type(L, -1) == LUA_TSTRING) + { + string modelname = lua_tostring(L, -1); + size_t pos = modelname.find_first_not_of(FILENAME_SAFE_CHARS); + if (pos != string::npos) + { + string path = locateResource(modelname); + if (path != "") + { + WFObj * obj = new WFObj(); + obj->load(path); + } + } + } + } + + return 0; } } diff --git a/ag.h b/ag.h index ab73e12..917224b 100644 --- a/ag.h +++ b/ag.h @@ -9,6 +9,7 @@ namespace ag void register_functions(lua_State * L); int ag_print(lua_State * L); int ag_println(lua_State * L); + int ag_loadModel(lua_State * L); } #endif diff --git a/anaglym.cc b/anaglym.cc index 29561f1..8e56a0e 100644 --- a/anaglym.cc +++ b/anaglym.cc @@ -1,8 +1,9 @@ -#include +#include "ag.h" #include #include /* exit() */ -#include "ag.h" +#include +#include using namespace std; static void usage(); @@ -91,3 +92,9 @@ static void register_libraries(lua_State * L) ag::register_functions(L); } + +string locateResource(const string & shortname) +{ + /* TODO: fill in */ + return ""; +} diff --git a/anaglym.h b/anaglym.h new file mode 100644 index 0000000..39bc2e7 --- /dev/null +++ b/anaglym.h @@ -0,0 +1,11 @@ + +#ifndef ANAGLYM_H +#define ANAGLYM_H + +#include + +#define FILENAME_SAFE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-" + +std::string locateResource(const std::string & shortname); + +#endif