added locateResource() and ag::ag_loadModel()

git-svn-id: svn://anubis/anaglym/trunk@10 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-09-14 03:58:53 +00:00
parent 795fcc13d6
commit ed80f25cee
4 changed files with 53 additions and 4 deletions

34
ag.cc
View File

@ -1,7 +1,10 @@
#include "anaglym.h"
#include "ag.h"
#include <iostream>
#include "wfobj/WFObj.hh"
#include <lua.hpp>
#include <iostream>
#include <string>
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;
}
}

1
ag.h
View File

@ -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

View File

@ -1,8 +1,9 @@
#include <iostream>
#include "ag.h"
#include <lua.hpp>
#include <stdlib.h> /* exit() */
#include "ag.h"
#include <iostream>
#include <string>
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 "";
}

11
anaglym.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef ANAGLYM_H
#define ANAGLYM_H
#include <string>
#define FILENAME_SAFE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-"
std::string locateResource(const std::string & shortname);
#endif