gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
отрефактори [code] максимальная читабельность, даже в угоду производительности,…
- User
отрефактори
function main() while true do wait(0) local veh = samem.player_vehicle[0] if veh ~= samem.nullptr then printStringNow( names[veh.nContactSurface], 1) -- Получаем указатель на pHandlingData local handlingDataPtr = veh.pHandlingData if handlingDataPtr ~= samem.nullptr then -- Преобразуем указатель в структуру tHandlingData local handlingData = samem.cast("tHandlingData *", handlingDataPtr) print("Mass:", handlingData.fMass) else print("pHandlingData is null") end end end endмаксимальная читабельность, даже в угоду производительности, комментарии на английском, схожесть с си синтаксисом
- Assistant
Here's a refactored version of your Lua function with improved readability, consistent naming conventions, and comments in English, while maintaining a syntax similar to C:
function main() -- Infinite loop to continually check vehicle information while true do wait(0) -- Yield to prevent freezing -- Get the first player vehicle local playerVehicle = samem.player_vehicle[0] -- Check if the vehicle pointer is not null if playerVehicle ~= samem.nullptr then -- Print the name of the contact surface of the vehicle printStringNow(names[playerVehicle.nContactSurface], 1) -- Get a pointer to the handling data of the vehicle local handlingDataPtr = playerVehicle.pHandlingData -- Check if the handling data pointer is not null if handlingDataPtr ~= samem.nullptr then -- Cast the pointer to the structure tHandlingData local handlingData = samem.cast("tHandlingData *", handlingDataPtr) -- Output the mass of the vehicle print("Mass:", handlingData.fMass) else -- Print a message if the handling data is null print("pHandlingData is null") end end end end - User
сделай чтобы комментарии типа все были справа и выровнены пробелами по линеечке
- Assistant
Certainly! Here’s the Lua function refactored with right-aligned comments:
function main() -- Infinite loop to continually check vehicle information while true do wait(0) -- Yield to prevent freezing -- Yield execution local playerVehicle = samem.player_vehicle[0] -- Get the first player vehicle if playerVehicle ~= samem.nullptr then -- Check if the vehicle pointer is not null printStringNow(names[playerVehicle.nContactSurface], 1) -- Print the name of the contact surface local handlingDataPtr = playerVehicle.pHandlingData -- Get a pointer to the handling data if handlingDataPtr ~= samem.nullptr then -- Check if the handling data pointer is not null local handlingData = samem.cast("tHandlingData *", handlingDataPtr) -- Cast pointer to tHandlingData print("Mass:", handlingData.fMass) -- Output the mass of the vehicle else -- Handle null case for the handling data pointer print("pHandlingData is null") -- Print a null handling data message end end end end