Hooks
static bool BeforeCvLuaFractal_lGetHeight(lua_State* L, int& result);static void AfterCvLuaFractal_lGetHeight(lua_State* L, int& result);static int ReplaceCvLuaFractal_lGetHeight(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvLuaFractal_lGetHeight>(host, &BeforeCvLuaFractal_lGetHeight);CivRegisterAfter<CivHooks::CvLuaFractal_lGetHeight>(host, &AfterCvLuaFractal_lGetHeight);CivRegisterReplace<CivHooks::CvLuaFractal_lGetHeight>(host, &ReplaceCvLuaFractal_lGetHeight);
Code
191int CvLuaFractal::lGetHeight(lua_State* L)192{193 //assume 'self' was pushed194 luaL_checktype(L, 1, LUA_TUSERDATA);195 CvFractal* pFractal = static_cast<CvFractal*>(lua_touserdata(L, 1));196197 int nargs = lua_gettop(L) - 1; //minus self198 switch(nargs)199 {200 case 1:201 {202 int percentage = lua_tointeger(L, 2);203 int height = pFractal->getHeightFromPercent(percentage);204 lua_pushinteger(L, height);205 }206 break;207 case 2:208 {209 int x = lua_tointeger(L, 2);210 int y = lua_tointeger(L, 3);211 int height = pFractal->getHeight(x, y);212 lua_pushinteger(L, height);213 }214 break;215 default:216 luaL_error(L, "Invalid number of arguments.");217 }218219 return 1;220}