anaglym/anaglym.cc
Josh Holtrop ed80f25cee added locateResource() and ag::ag_loadModel()
git-svn-id: svn://anubis/anaglym/trunk@10 99a6e188-d820-4881-8870-2d33a10e2619
2009-09-14 03:58:53 +00:00

101 lines
2.0 KiB
C++

#include "ag.h"
#include <lua.hpp>
#include <stdlib.h> /* exit() */
#include <iostream>
#include <string>
using namespace std;
static void usage();
static void report_errors(lua_State * L, int status);
static void register_libraries(lua_State * L);
int main(int argc, char * argv[])
{
const char * program = NULL;
for (int i = 1; i < argc; i++)
{
if (argv[i][0] != '-')
{
if (program == NULL)
{
program = argv[i];
}
else
{
cerr << "Warning: argument " << argv[i] << " ignored!" << endl;
}
}
else
{
cerr << "Warning: Unrecognized option '" << argv[i]+1
<< "'" << endl;
}
}
if (program == NULL)
{
usage();
}
lua_State * L = lua_open();
register_libraries(L);
int s = luaL_loadfile(L, program);
if ( s == 0 )
{
// execute Lua program
s = lua_pcall(L, 0, LUA_MULTRET, 0);
}
else
{
cerr << "Warning: problem loading '" << program << "'" << endl;
return 1;
}
report_errors(L, s);
lua_close(L);
return 0;
}
static void report_errors(lua_State * L, int status)
{
if ( status!=0 )
{
cerr << "-- " << lua_tostring(L, -1) << endl;
lua_pop(L, 1); // remove error message
}
}
static void usage()
{
cerr << "Usage: anaglym [options] program.lua[c]" << endl;
exit(42);
}
static void register_libraries(lua_State * L)
{
/* Load the Lua string library */
lua_pushcfunction(L, luaopen_string);
lua_pcall(L, 0, 0, 0);
/* Load the Lua math library */
lua_pushcfunction(L, luaopen_math);
lua_pcall(L, 0, 0, 0);
/* Load the Lua table library */
lua_pushcfunction(L, luaopen_table);
lua_pcall(L, 0, 0, 0);
ag::register_functions(L);
}
string locateResource(const string & shortname)
{
/* TODO: fill in */
return "";
}