Established a connection between the Region objects and lua

This commit is contained in:
Kayne Ruse
2014-03-28 04:11:34 +11:00
parent 38b603fc8f
commit 4cff57fe71
5 changed files with 58 additions and 4 deletions
+1 -1
View File
@@ -42,7 +42,7 @@ void LuaGenerator::Create(Region** const ptr, int width, int height, int depth,
//generate the lua-driven maps //generate the lua-driven maps
lua_getglobal(state, "CreateRegion"); lua_getglobal(state, "CreateRegion");
lua_pushlightuserdata(state, ptr); lua_pushlightuserdata(state, *ptr);
lua_pcall(state, 1, 0, 0); lua_pcall(state, 1, 0, 0);
} }
+48 -2
View File
@@ -21,7 +21,53 @@
*/ */
#include "region_api.hpp" #include "region_api.hpp"
LUAMOD_API int luaopen_regionapi(lua_State* L) { #include "region.hpp"
//TODO: stuff
static int setTile(lua_State* L) {
// Region* ptr = lua_touserdata(L, 1);
// ptr->SetTile
}
static int getTile(lua_State* L) {
//TODO
}
static int getWidth(lua_State* L) {
//TODO
}
static int getHeight(lua_State* L) {
//TODO
}
static int getDepth(lua_State* L) {
//TODO
}
static int getX(lua_State* L) {
Region* ptr = (Region*)lua_touserdata(L, 1);
lua_pushinteger(L, ptr->GetX());
return 1;
}
static int getY(lua_State* L) {
Region* ptr = (Region*)lua_touserdata(L, 1);
lua_pushinteger(L, ptr->GetY());
return 1;
}
static const luaL_Reg regionlib[] = {
{"SetTile",setTile},
{"GetTile",getTile},
{"GetWidth",getWidth},
{"GetHeight",getHeight},
{"GetDepth",getDepth},
{"GetX",getX},
{"GetY",getY},
{nullptr, nullptr}
};
LUAMOD_API int luaopen_regionapi(lua_State* L) {
luaL_newlib(L, regionlib);
return 1; return 1;
} }
+1 -1
View File
@@ -24,7 +24,7 @@
#include "lua/lua.hpp" #include "lua/lua.hpp"
#define LUA_REGIONLIBNAME "region" #define LUA_REGIONLIBNAME "Region"
LUAMOD_API int luaopen_regionapi(lua_State* L); LUAMOD_API int luaopen_regionapi(lua_State* L);
#endif #endif
+5 -1
View File
@@ -1 +1,5 @@
print("Lua script check OK") print("Lua script check OK (./rsc)")
function CreateRegion(r)
print(Region.GetX(r), Region.GetY(r))
end
+4
View File
@@ -110,6 +110,10 @@ void ServerApplication::Init(int argc, char** argv) {
//finalize the startup //finalize the startup
cout << "Startup completed successfully" << endl; cout << "Startup completed successfully" << endl;
//debugging
mapPager.GetRegion(0,0);
mapPager.GetRegion(128,256);
} }
void ServerApplication::Loop() { void ServerApplication::Loop() {