diff options
author | Elias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com> | 2020-11-04 16:44:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 16:44:42 +0100 |
commit | 5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (patch) | |
tree | c980d614fec4a5495798be3e79e033229062c3cd /src/script/lua_api/l_nodetimer.cpp | |
parent | 28f6a79706b088c37268a59d90878220dc4ef9c7 (diff) | |
parent | 3af10766fd2b58b068e970266724d7eb10e9316b (diff) | |
download | dragonfireclient-5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc.tar.xz |
Merge branch 'master' into master
Diffstat (limited to 'src/script/lua_api/l_nodetimer.cpp')
-rw-r--r-- | src/script/lua_api/l_nodetimer.cpp | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/script/lua_api/l_nodetimer.cpp b/src/script/lua_api/l_nodetimer.cpp index c2df52c05..621af5fd3 100644 --- a/src/script/lua_api/l_nodetimer.cpp +++ b/src/script/lua_api/l_nodetimer.cpp @@ -22,27 +22,28 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverenvironment.h" #include "map.h" - -int NodeTimerRef::gc_object(lua_State *L) { +int NodeTimerRef::gc_object(lua_State *L) +{ NodeTimerRef *o = *(NodeTimerRef **)(lua_touserdata(L, 1)); delete o; return 0; } -NodeTimerRef* NodeTimerRef::checkobject(lua_State *L, int narg) +NodeTimerRef *NodeTimerRef::checkobject(lua_State *L, int narg) { luaL_checktype(L, narg, LUA_TUSERDATA); void *ud = luaL_checkudata(L, narg, className); - if(!ud) luaL_typerror(L, narg, className); - return *(NodeTimerRef**)ud; // unbox pointer + if (!ud) + luaL_typerror(L, narg, className); + return *(NodeTimerRef **)ud; // unbox pointer } int NodeTimerRef::l_set(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - f32 t = readParam<float>(L,2); - f32 e = readParam<float>(L,3); + f32 t = readParam<float>(L, 2); + f32 e = readParam<float>(L, 3); o->m_map->setNodeTimer(NodeTimer(t, e, o->m_p)); return 0; } @@ -51,7 +52,7 @@ int NodeTimerRef::l_start(lua_State *L) { MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); - f32 t = readParam<float>(L,2); + f32 t = readParam<float>(L, 2); o->m_map->setNodeTimer(NodeTimer(t, 0, o->m_p)); return 0; } @@ -69,7 +70,7 @@ int NodeTimerRef::l_is_started(lua_State *L) MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); NodeTimer t = o->m_map->getNodeTimer(o->m_p); - lua_pushboolean(L,(t.timeout != 0)); + lua_pushboolean(L, (t.timeout != 0)); return 1; } @@ -78,7 +79,7 @@ int NodeTimerRef::l_get_timeout(lua_State *L) MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); NodeTimer t = o->m_map->getNodeTimer(o->m_p); - lua_pushnumber(L,t.timeout); + lua_pushnumber(L, t.timeout); return 1; } @@ -87,7 +88,7 @@ int NodeTimerRef::l_get_elapsed(lua_State *L) MAP_LOCK_REQUIRED; NodeTimerRef *o = checkobject(L, 1); NodeTimer t = o->m_map->getNodeTimer(o->m_p); - lua_pushnumber(L,t.elapsed); + lua_pushnumber(L, t.elapsed); return 1; } @@ -110,7 +111,7 @@ void NodeTimerRef::Register(lua_State *L) lua_pushliteral(L, "__metatable"); lua_pushvalue(L, methodtable); - lua_settable(L, metatable); // hide metatable from Lua getmetatable() + lua_settable(L, metatable); // hide metatable from Lua getmetatable() lua_pushliteral(L, "__index"); lua_pushvalue(L, methodtable); @@ -120,22 +121,17 @@ void NodeTimerRef::Register(lua_State *L) lua_pushcfunction(L, gc_object); lua_settable(L, metatable); - lua_pop(L, 1); // drop metatable + lua_pop(L, 1); // drop metatable - luaL_openlib(L, 0, methods, 0); // fill methodtable - lua_pop(L, 1); // drop methodtable + luaL_openlib(L, 0, methods, 0); // fill methodtable + lua_pop(L, 1); // drop methodtable // Cannot be created from Lua - //lua_register(L, className, create_object); + // lua_register(L, className, create_object); } const char NodeTimerRef::className[] = "NodeTimerRef"; -const luaL_Reg NodeTimerRef::methods[] = { - luamethod(NodeTimerRef, start), - luamethod(NodeTimerRef, set), - luamethod(NodeTimerRef, stop), - luamethod(NodeTimerRef, is_started), - luamethod(NodeTimerRef, get_timeout), - luamethod(NodeTimerRef, get_elapsed), - {0,0} -}; +const luaL_Reg NodeTimerRef::methods[] = {luamethod(NodeTimerRef, start), + luamethod(NodeTimerRef, set), luamethod(NodeTimerRef, stop), + luamethod(NodeTimerRef, is_started), luamethod(NodeTimerRef, get_timeout), + luamethod(NodeTimerRef, get_elapsed), {0, 0}}; |