2007-10-14 15:11:18 +03:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
2008-08-02 18:08:03 +03:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2007-10-14 15:11:18 +03:00
|
|
|
#include "lua.h"
|
|
|
|
#include "lualib.h"
|
2008-08-02 18:08:03 +03:00
|
|
|
#include "lauxlib.h"
|
|
|
|
|
|
|
|
#ifndef _MSC_VER
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-11-19 00:58:28 +02:00
|
|
|
//#include <luabind/luabind.hpp>
|
|
|
|
//#include <luabind/function.hpp>
|
|
|
|
//#include <luabind/class.hpp>
|
2007-10-14 15:11:18 +03:00
|
|
|
#include "CLuaHandler.h"
|
2007-10-27 22:38:48 +03:00
|
|
|
#include "boost/filesystem.hpp"
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2007-10-14 15:11:18 +03:00
|
|
|
void piszpowitanie2(std::string i) //simple global function for testing
|
|
|
|
{
|
|
|
|
std::cout<<"powitanie2zc++. Liczba dnia to " << i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CLuaHandler::CLuaHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
CLuaHandler::~CLuaHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
void CLuaHandler::test()
|
|
|
|
{
|
2008-07-25 20:28:28 +03:00
|
|
|
//int iErr = 0;
|
|
|
|
//lua_State *lua = lua_open (); // Open Lua
|
|
|
|
//LUA_OPEN_LIB(lua, luaopen_base);
|
|
|
|
//LUA_OPEN_LIB(lua, luaopen_io);
|
|
|
|
//if ((iErr = luaL_loadfile (lua, "scripts/lua/objects/0023_marletto_tower.lua")) == 0)
|
|
|
|
//{
|
|
|
|
// // Call main...
|
|
|
|
// if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0)
|
|
|
|
// {
|
|
|
|
// lua_pushstring (lua, "rightText");
|
|
|
|
// lua_gettable (lua, LUA_GLOBALSINDEX);
|
|
|
|
// lua_pcall (lua, 0, 0, 0);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//lua_close (lua);
|
2008-08-02 18:08:03 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-10-27 22:38:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> * CLuaHandler::searchForScripts(std::string fol)
|
|
|
|
{
|
|
|
|
std::vector<std::string> * ret = new std::vector<std::string> ();
|
|
|
|
boost::filesystem::path folder(fol);
|
|
|
|
if (!boost::filesystem::exists(folder))
|
2008-08-04 12:05:52 +03:00
|
|
|
#ifndef __GNUC__
|
2007-10-27 22:38:48 +03:00
|
|
|
throw new std::exception("No such folder!");
|
2008-08-04 12:05:52 +03:00
|
|
|
#else
|
|
|
|
throw new std::exception();
|
|
|
|
#endif
|
2007-10-27 22:38:48 +03:00
|
|
|
boost::filesystem::directory_iterator end_itr;
|
|
|
|
for
|
|
|
|
(
|
|
|
|
boost::filesystem::directory_iterator it(folder);
|
|
|
|
it!=end_itr;
|
|
|
|
it++
|
|
|
|
)
|
|
|
|
{
|
|
|
|
if(boost::algorithm::ends_with((it->path().leaf()),".lua"))
|
|
|
|
{
|
|
|
|
ret->push_back(fol+"/"+(it->path().leaf()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
2007-11-19 00:58:28 +02:00
|
|
|
}
|
|
|
|
std::vector<std::string> * CLuaHandler::functionList(std::string file)
|
|
|
|
{
|
|
|
|
std::vector<std::string> * ret = new std::vector<std::string> ();
|
|
|
|
char linia[500];
|
|
|
|
std::ifstream is(file.c_str());
|
|
|
|
while (!is.eof())
|
|
|
|
{
|
|
|
|
is.getline(linia,500);
|
|
|
|
std::string ss(linia);
|
|
|
|
boost::algorithm::trim_left(ss);
|
|
|
|
if (boost::algorithm::starts_with(ss,"local"))
|
|
|
|
boost::algorithm::erase_first(ss,"local ");
|
|
|
|
if (boost::algorithm::starts_with(ss,"function"))
|
|
|
|
{
|
|
|
|
boost::algorithm::erase_first(ss,"function ");
|
|
|
|
int ps = ss.find_first_of(' ');
|
|
|
|
int op = ss.find_first_of('(');
|
|
|
|
if (ps<0)
|
|
|
|
ps = ss.length()-1;
|
|
|
|
if (op<0)
|
|
|
|
op = ss.length()-1;
|
|
|
|
ps = std::min(ps,op);
|
|
|
|
ret->push_back(ss.substr(0,ps));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
is.close();
|
|
|
|
return ret;
|
2008-08-02 18:08:03 +03:00
|
|
|
}
|