1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-06 09:09:40 +02:00

Partially done object scripting and interactions.

Most of 0.4 ;)
This commit is contained in:
Michał W. Urbańczyk
2007-11-18 22:58:28 +00:00
parent 8b73ab8492
commit 556311c9ab
31 changed files with 2201 additions and 1283 deletions

View File

@@ -3,9 +3,9 @@
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <luabind/luabind.hpp>
#include <luabind/function.hpp>
#include <luabind/class.hpp>
//#include <luabind/luabind.hpp>
//#include <luabind/function.hpp>
//#include <luabind/class.hpp>
#include "CLuaHandler.h"
#include "boost/filesystem.hpp"
#include <boost/algorithm/string.hpp>
@@ -28,27 +28,35 @@ void CLuaHandler::test()
LUA_OPEN_LIB(lua, luaopen_base);
LUA_OPEN_LIB(lua, luaopen_io);
if ((iErr = luaL_loadfile (lua, "test.lua")) == 0)
{
//luabind::open(lua);
//luabind::module(lua)
//[
// luabind::class_<int3>("int3")
// //.def(luabind::constructor<>())
// //.def(luabind::constructor<const int&,const int&,const int&>())
// .def_readwrite("x", &int3::x)
// .def_readwrite("y", &int3::y)
// .def_readwrite("z", &int3::z)
//];
//luabind::module(lua)
//[
// luabind::def("powitanie",&piszpowitanie2)
//];
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)
{
luabind::open(lua);
luabind::module(lua)
[
luabind::def("powitanie",&piszpowitanie2)
];
//int ret = luabind::call_function<int>(lua, "helloWorld2");
lua_pushstring (lua, "helloWorld2");
lua_gettable (lua, LUA_GLOBALSINDEX);
lua_pcall (lua, 0, 0, 0);
//lua_pushstring (lua, "helloWorld2");
//lua_gettable (lua, LUA_GLOBALSINDEX);
//lua_pcall (lua, 0, 0, 0);
// Push the function name onto the stack
lua_pushstring (lua, "helloWorld");
lua_pushstring (lua, "rightText");
lua_gettable (lua, LUA_GLOBALSINDEX);
lua_pcall (lua, 0, 0, 0);
}
@@ -77,4 +85,32 @@ std::vector<std::string> * CLuaHandler::searchForScripts(std::string fol)
}
}
return ret;
}
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;
}