diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index fa0eee598..1a9202f57 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -152,7 +152,8 @@ enum cameraf { camera_momz, camera_pan, camera_pitch, - camera_pnum + camera_pnum, + camera_freecam, }; @@ -174,6 +175,7 @@ static const char *const camera_opt[] = { "pan", "pitch", "pnum", + "freecam", NULL}; enum hudpatch { @@ -332,10 +334,43 @@ static int camera_get(lua_State *L) case camera_pnum: lua_pushinteger(L, camnum); break; + case camera_freecam: + lua_pushboolean(L, cam->freecam); + break; } return 1; } +static int lib_getCamera(lua_State *L) +{ + // No cameras on dedicated + if (dedicated) + return 0; + + if (lua_type(L, 2) == LUA_TNUMBER) + { + int i = lua_tonumber(L, 2); + + if (i < 0 || i > splitscreen) + return 0; + + LUA_PushUserdata(L, &camera[i], META_CAMERA); + return 1; + } + + return 0; +} + +static int lib_lenCamera(lua_State *L) +{ + if (dedicated) + lua_pushinteger(L, 0); + else + lua_pushinteger(L, splitscreen+1); // splitscreen == 0 -> 1 active camera, splitscreen == 1 -> 2 cameras and so on + + return 1; +} + // // lib_draw // @@ -1671,6 +1706,16 @@ int LUA_HudLib(lua_State *L) lua_setfield(L, -2, "__index"); lua_pop(L,1); + lua_newuserdata(L, 0); + lua_createtable(L, 0, 2); + lua_pushcfunction(L, lib_getCamera); + lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, lib_lenCamera); + lua_setfield(L, -2, "__len"); + lua_setmetatable(L, -2); + lua_setglobal(L, "cameras"); + luaL_register(L, "hud", lib_hud); return 0; }