Skip to content

Commit

Permalink
Move isInArray to Lua (#2095)
Browse files Browse the repository at this point in the history
  • Loading branch information
WibbenZ authored and ranisalt committed Jan 28, 2017
1 parent c5ab889 commit 1ae8483
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 25 deletions.
9 changes: 9 additions & 0 deletions data/global.lua
Expand Up @@ -33,6 +33,15 @@ function getFormattedWorldTime()
return hours .. ':' .. minutes
end

table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then
return true
end
end
return false
end

string.split = function(str, sep)
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do
Expand Down
2 changes: 2 additions & 0 deletions data/lib/compat/compat.lua
Expand Up @@ -1040,6 +1040,8 @@ function doSetCreatureOutfit(cid, outfit, time)
return true
end

function isInArray(array, value) return table.contains(array, value) end

function doCreateItem(itemid, count, pos)
local tile = Tile(pos)
if not tile then
Expand Down
24 changes: 0 additions & 24 deletions src/luascript.cpp
Expand Up @@ -974,9 +974,6 @@ void LuaScriptInterface::registerFunctions()
//doChallengeCreature(cid, target)
lua_register(luaState, "doChallengeCreature", LuaScriptInterface::luaDoChallengeCreature);

//isInArray(array, value)
lua_register(luaState, "isInArray", LuaScriptInterface::luaIsInArray);

//addEvent(callback, delay, ...)
lua_register(luaState, "addEvent", LuaScriptInterface::luaAddEvent);

Expand Down Expand Up @@ -3322,27 +3319,6 @@ int LuaScriptInterface::luaGetDepotId(lua_State* L)
return 1;
}

int LuaScriptInterface::luaIsInArray(lua_State* L)
{
//isInArray(array, value)
if (!isTable(L, 1)) {
pushBoolean(L, false);
return 1;
}

lua_pushnil(L);
while (lua_next(L, 1)) {
if (lua_equal(L, 2, -1) != 0) {
pushBoolean(L, true);
return 1;
}
lua_pop(L, 1);
}

pushBoolean(L, false);
return 1;
}

int LuaScriptInterface::luaDoSetCreatureLight(lua_State* L)
{
//doSetCreatureLight(cid, lightLevel, lightColor, time)
Expand Down
1 change: 0 additions & 1 deletion src/luascript.h
Expand Up @@ -458,7 +458,6 @@ class LuaScriptInterface
static int luaDoChallengeCreature(lua_State* L);

static int luaDebugPrint(lua_State* L);
static int luaIsInArray(lua_State* L);
static int luaAddEvent(lua_State* L);
static int luaStopEvent(lua_State* L);

Expand Down

0 comments on commit 1ae8483

Please sign in to comment.