Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created July 11, 2013 13:57
Show Gist options
  • Save Ratstail91/5975662 to your computer and use it in GitHub Desktop.
Save Ratstail91/5975662 to your computer and use it in GitHub Desktop.
oh dear god, what have I done?
void openCustomLibraries(lua_State* L) {
//-------------------------
// Define the map library for lua
//-------------------------
//push the initial table
lua_newtable(L);
lua_pushcfunction(L, [](lua_State* l) -> int {
//require 4 parameters
while (lua_gettop(l) < 4) {
lua_pushnumber(l, -1);
}
Map::GetSingletonPtr()->Generate(
lua_tonumber(l, 1),
lua_tonumber(l, 2),
lua_tonumber(l, 3),
lua_tonumber(l, 4)
);
return 0;
});
lua_setfield(L, 1, "Generate");
lua_pushcfunction(L, [](lua_State* l) -> int {
Map::GetSingletonPtr()->Clear();
return 0;
});
lua_setfield(L, 1, "Clear");
lua_pushcfunction(L, [](lua_State* l) -> int {
Map::GetSingletonPtr()->InsertLayer(lua_tonumber(l, 1), lua_tonumber(l, 2));
return 0;
});
lua_setfield(L, 1, "InsertLayer");
lua_pushcfunction(L, [](lua_State* l) -> int {
Map::GetSingletonPtr()->DeleteLayer(lua_tonumber(l, 1));
return 0;
});
lua_setfield(L, 1, "DeleteLayer");
lua_pushcfunction(L, [](lua_State* l) -> int {
int ret = Map::GetSingletonPtr()->SetTile(
lua_tonumber(l, 1),
lua_tonumber(l, 2),
lua_tonumber(l, 3),
lua_tonumber(l, 4)
);
lua_pushnumber(l, ret);
return 1;
});
lua_setfield(L, 1, "SetTile");
lua_pushcfunction(L, [](lua_State* l) -> int {
int ret = Map::GetSingletonPtr()->SetTile(
lua_tonumber(l, 1),
lua_tonumber(l, 2),
lua_tonumber(l, 3)
);
lua_pushnumber(l, ret);
return 1;
});
lua_setfield(L, 1, "GetTile");
lua_pushcfunction(L, [](lua_State* l) -> int {
int ret = Map::GetSingletonPtr()->GetLayerCount();
lua_pushnumber(l, ret);
return 1;
});
lua_setfield(L, 1, "GetLayerCount");
lua_pushcfunction(L, [](lua_State* l) -> int {
int ret = Map::GetSingletonPtr()->GetWidth();
lua_pushnumber(l, ret);
return 1;
});
lua_setfield(L, 1, "GetWidth");
lua_pushcfunction(L, [](lua_State* l) -> int {
int ret = Map::GetSingletonPtr()->GetHeight();
lua_pushnumber(l, ret);
return 1;
});
lua_setfield(L, 1, "GetHeight");
//finalize this library
lua_setglobal(L, "map");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment