Commit cc677d2d authored by James R.'s avatar James R.
Browse files

Merge branch 'com-buf-insert-text-optional-player' into 'next'

Make the player optional for COM_BufInsertText and COM_BufAddText.

See merge request !1093
parents cc508d0b 03b7a1c3
...@@ -236,15 +236,14 @@ static int lib_comAddCommand(lua_State *L) ...@@ -236,15 +236,14 @@ static int lib_comAddCommand(lua_State *L)
static int lib_comBufAddText(lua_State *L) static int lib_comBufAddText(lua_State *L)
{ {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
player_t *plr; player_t *plr = NULL;
if (n < 2) if (n < 2)
return luaL_error(L, "COM_BufAddText requires two arguments: player and text."); return luaL_error(L, "COM_BufAddText requires two arguments: player and text.");
NOHUD NOHUD
lua_settop(L, 2); lua_settop(L, 2);
plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); if (!lua_isnoneornil(L, 1))
if (!plr) plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
return LUA_ErrInvalid(L, "player_t"); if (plr && plr != &players[consoleplayer])
if (plr != &players[consoleplayer])
return 0; return 0;
COM_BufAddTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_SAFE); COM_BufAddTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_SAFE);
return 0; return 0;
...@@ -253,15 +252,14 @@ static int lib_comBufAddText(lua_State *L) ...@@ -253,15 +252,14 @@ static int lib_comBufAddText(lua_State *L)
static int lib_comBufInsertText(lua_State *L) static int lib_comBufInsertText(lua_State *L)
{ {
int n = lua_gettop(L); /* number of arguments */ int n = lua_gettop(L); /* number of arguments */
player_t *plr; player_t *plr = NULL;
if (n < 2) if (n < 2)
return luaL_error(L, "COM_BufInsertText requires two arguments: player and text."); return luaL_error(L, "COM_BufInsertText requires two arguments: player and text.");
NOHUD NOHUD
lua_settop(L, 2); lua_settop(L, 2);
plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); if (!lua_isnoneornil(L, 1))
if (!plr) plr = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
return LUA_ErrInvalid(L, "player_t"); if (plr && plr != &players[consoleplayer])
if (plr != &players[consoleplayer])
return 0; return 0;
COM_BufInsertTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_SAFE); COM_BufInsertTextEx(va("%s\n", luaL_checkstring(L, 2)), COM_SAFE);
return 0; return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment