diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 9a3e676d5fd6168fd64bfaaa44466a5e85e8949c..306ffaf9482dd996fb10d637ab83f70998fcb393 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -384,6 +384,59 @@ static int camera_get(lua_State *L) return 1; } +static int camera_set(lua_State *L) +{ + camera_t *cam = *((camera_t **)luaL_checkudata(L, 1, META_CAMERA)); + enum cameraf field = luaL_checkoption(L, 2, NULL, camera_opt); + + I_Assert(cam != NULL); + + switch(field) + { + case camera_subsector: + case camera_floorz: + case camera_ceilingz: + case camera_height: + case camera_radius: + return luaL_error(L, LUA_QL("camera_t") " field " LUA_QS " should not be set directly.", camera_opt[field]); + case camera_chase: + if (cam == &camera) + CV_SetValue(&cv_chasecam, (INT32)luaL_checkboolean(L, 3)); + else if (cam == &camera2) + CV_SetValue(&cv_chasecam2, (INT32)luaL_checkboolean(L, 3)); + else // ??? this should never happen, but ok + cam->chase = luaL_checkboolean(L, 3); + break; + case camera_aiming: + cam->aiming = luaL_checkangle(L, 3); + break; + case camera_x: + cam->x = luaL_checkfixed(L, 3); + break; + case camera_y: + cam->y = luaL_checkfixed(L, 3); + break; + case camera_z: + cam->z = luaL_checkfixed(L, 3); + break; + case camera_angle: + cam->angle = luaL_checkangle(L, 3); + break; + case camera_momx: + cam->momx = luaL_checkfixed(L, 3); + break; + case camera_momy: + cam->momy = luaL_checkfixed(L, 3); + break; + case camera_momz: + cam->momz = luaL_checkfixed(L, 3); + break; + default: + return luaL_error(L, LUA_QL("camera_t") " has no field named " LUA_QS, camera_opt[field]); + } + return 0; +} + // // lib_draw // @@ -1283,6 +1336,9 @@ int LUA_HudLib(lua_State *L) luaL_newmetatable(L, META_CAMERA); lua_pushcfunction(L, camera_get); lua_setfield(L, -2, "__index"); + + lua_pushcfunction(L, camera_set); + lua_setfield(L, -2, "__newindex"); lua_pop(L,1); luaL_register(L, "hud", lib_hud); diff --git a/src/lua_script.c b/src/lua_script.c index 6faff8729609bdf3a7e758a81829cb9ac4a74900..54ab124fc5e2eac57725717292a085f662ff97e3 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -393,6 +393,14 @@ int LUA_PushGlobals(lua_State *L, const char *word) } else if (fastcmp(word, "mouse2")) { LUA_PushUserdata(L, &mouse2, META_MOUSE); return 1; + } else if (fastcmp(word, "camera")) { + LUA_PushUserdata(L, &camera, META_CAMERA); + return 1; + } else if (fastcmp(word, "camera2")) { + if (!splitscreen) + return 0; + LUA_PushUserdata(L, &camera2, META_CAMERA); + return 1; } return 0; }