Armas agora sao carregadas de lua
[Projeto-PCG.git] / luaenv.cpp
bloba14e704e8263dab52871dc86f011a81dec5797a9
1 #include "luaenv.h"
3 void luaRun::registerScripts() {
4 registerScript("helloworld.lua");
7 void luaRun::registerScript(const std::string &name) {
8 Script novo(name);
9 scripts.push_back(novo);
12 lua_State* newState() {
13 lua_State* l = lua_open();
14 luaL_openlibs(l);
15 return l;
18 void doLuaFile(lua_State* l,std::string file) {
19 if (luaL_dofile(l, file.c_str())) {
20 printf("%s\n", lua_tostring(l, -1));
24 void registerFunction(lua_State* l, std::string name, lua_CFunction function) {
25 lua_pushcfunction(l, function);
26 lua_setglobal(l, name.c_str());
29 void luaRun::loadScripts() {
30 std::vector<Script >::iterator it;
31 for (it = scripts.begin();it != scripts.end(); it++) {
32 if (it->L != NULL) lua_close(it->L);
33 it->L = newState();
34 doLuaFile(it->L,it->name);