@@ -2696,7 +2696,32 @@ int ObjectRef::l_set_lighting(lua_State *L)
26962696 lighting.bloom_radius = getfloatfield_default (L, -1 , " radius" , lighting.bloom_radius );
26972697 }
26982698 lua_pop (L, 1 ); // bloom
2699- }
2699+
2700+ lua_getfield (L, 2 , " color_transform_matrix" );
2701+
2702+ // if none or nil, keep color transform matrix unchanged
2703+ if (!lua_isnoneornil (L, -1 )) {
2704+ if (!lua_istable (L, -1 ))
2705+ throw LuaError (" vision_effects.color_transform_matrix is not a table" );
2706+
2707+ for (int row = 1 ; row <= 3 ; ++row) {
2708+ lua_rawgeti (L, -1 , row);
2709+ if (!lua_istable (L, -1 ))
2710+ throw LuaError (" color_transform_matrix should be in format {{a, b, c},{d, e, f},{g, a, h}}" );
2711+
2712+ for (int col = 1 ; col <= 3 ; ++col) {
2713+ lua_rawgeti (L, -1 , col);
2714+ if (!lua_isnumber (L, -1 ))
2715+ throw LuaError (" color_transform_matrix should be in format {{a, b, c},{d, e, f},{g, a, h}}" );
2716+
2717+ lighting.vision_effects .color_transform_matrix [(row - 1 ) * 3 + (col - 1 )] = (float )lua_tonumber (L, -1 );
2718+ lua_pop (L, 1 ); // Pop the value at [row][col]
2719+ }
2720+ lua_pop (L, 1 ); // Pop the row table
2721+ }
2722+ }
2723+ lua_pop (L, 1 ); // color_transform_matrix
2724+ }
27002725
27012726 getServer (L)->setLighting (player, lighting);
27022727 return 0 ;
@@ -2748,6 +2773,17 @@ int ObjectRef::l_get_lighting(lua_State *L)
27482773 lua_pushnumber (L, lighting.bloom_radius );
27492774 lua_setfield (L, -2 , " radius" );
27502775 lua_setfield (L, -2 , " bloom" );
2776+ lua_newtable (L); // "color_transform_matrix"
2777+ // Create the nested table structure {{a, b, c}, {d, e, f}, {g, h, i}}
2778+ for (int row = 0 ; row < 3 ; row++) {
2779+ lua_newtable (L); // Create inner row table
2780+ for (int col = 0 ; col < 3 ; col++) {
2781+ lua_pushnumber (L, lighting.vision_effects .color_transform_matrix [row * 3 + col]); // Push the value
2782+ lua_rawseti (L, -2 , col + 1 ); // Set value in inner table with 1-based indexing
2783+ }
2784+ lua_rawseti (L, -2 , row + 1 ); // Set inner table in the outer matrix table
2785+ }
2786+ lua_setfield (L, -2 , " color_transform_matrix" );
27512787 return 1 ;
27522788}
27532789
0 commit comments