Skip to content

Commit

Permalink
sim.signs.delete() api function
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Jul 16, 2017
1 parent 6d141b0 commit b8ce522
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/lua/LuaScriptInterface.cpp
Expand Up @@ -623,7 +623,11 @@ int LuaScriptInterface::simulation_signNewIndex(lua_State *l)
if (!key.compare("text"))
{
const char *temp = luaL_checkstring(l, 3);
luacon_sim->signs[id].text = format::CleanString(temp, false, true, true).substr(0, 45);
std::string cleaned = format::CleanString(temp, false, true, true).substr(0, 45);
if (!cleaned.empty())
luacon_sim->signs[id].text = cleaned;
else
luaL_error(l, "Text is empty");
return 0;
}
else if (!key.compare("justification"))
Expand Down Expand Up @@ -660,7 +664,7 @@ int LuaScriptInterface::simulation_signNewIndex(lua_State *l)
return 0;
}

//creates a new sign at the first open index
// Creates a new sign at the first open index
int LuaScriptInterface::simulation_newsign(lua_State *l)
{
if (luacon_sim->signs.size() >= MAXSIGNS)
Expand All @@ -683,6 +687,17 @@ int LuaScriptInterface::simulation_newsign(lua_State *l)
return 1;
}

// Deletes a sign
int simulation_deletesign(lua_State *l)
{
int signID = luaL_checkinteger(l, 1);
if (signID <= 0 || signID > (int)luacon_sim->signs.size())
return luaL_error(l, "Sign doesn't exist");

luacon_sim->signs.erase(luacon_sim->signs.begin()+signID-1);
return 1;
}

//// Begin Simulation API

StructProperty * LuaScriptInterface::particleProperties;
Expand Down Expand Up @@ -814,6 +829,8 @@ void LuaScriptInterface::initSimulationAPI()
}
lua_pushcfunction(l, simulation_newsign);
lua_setfield(l, -2, "new");
lua_pushcfunction(l, simulation_deletesign);
lua_setfield(l, -2, "delete");
lua_setfield(l, -2, "signs");
}

Expand Down

0 comments on commit b8ce522

Please sign in to comment.