create Script class
[Tsunagari.git] / src / script.cpp
blob936b21ff3ae55104b52f66bbc7c1db5f144065fa
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** script.cpp **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #include "log.h"
8 #include "script.h"
10 Script::Script()
12 L = lua_open();
13 luaL_openlibs(L);
16 void Script::addFn(const char* name, lua_CFunction fn)
18 lua_register(L, name, fn);
21 void Script::addInt(const char* name, lua_Integer i)
23 lua_pushinteger(L, i);
24 lua_setglobal(L, name);
27 void Script::addData(const char* name, void* data)
29 lua_pushlightuserdata(L, data);
30 lua_setglobal(L, name);
33 void Script::run(const char* fn)
35 if (luaL_loadfile(L, fn)) {
36 Log::err("Script::run", std::string("Couldn't load file: ") +
37 lua_tostring(L, -1));
38 return;
40 lua_call(L, 0, 0);
43 Script::~Script()
45 lua_close(L);