-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.cpp
42 lines (37 loc) · 1.11 KB
/
map.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "map.h"
Map::Map()
{
this->L = luaL_newstate();
luaL_openlibs(this->L);
}
Map::~Map()
{
lua_close(this->L);
}
int Map::GetPos(std::string layer, olc::vi2d pos)
{
lua_getglobal(this->L, "GetPos");
lua_pushstring(this->L, layer.c_str());
lua_pushinteger(this->L, pos.x);
lua_pushinteger(this->L, pos.y);
lua_pcall(this->L, 3, 1, 0);
int res = lua_tonumber(this->L, -1);
lua_pop(this->L, 1);
return res;
}
void Map::SetPos(std::string layer, olc::vi2d pos, int val)
{
lua_getglobal(this->L, "SetPos");
lua_pushstring(this->L, layer.c_str());
lua_pushinteger(this->L, pos.x);
lua_pushinteger(this->L, pos.y);
lua_pushinteger(this->L, val);
lua_pcall(this->L, 4, 0, 0);
}
void Map::Load()
{
if (luaL_loadfile(this->L, this->mapFilePath.string().c_str()) != LUA_OK)
throw std::runtime_error("Couldn't load map manager script, ensure assets/scripts/mapmanager.lua exists");
if (lua_pcall(this->L, 0, LUA_MULTRET, 0) != LUA_OK)
throw std::runtime_error("Couldn't run map manager script: " + std::string(lua_tostring(this->L, -1)));
}