Dump the properties of Lua wrapper

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Dump the properties of Lua wrapper

Post by michaelm75au »

I may have mentioned this in passing before, but I thought I would update it.
You can get a list of the property names of a Lua wrapper by a query on the wrapper.fields. This is handy sometimes to see what is available in case the WIKI is not up to date.

Example.
[font="Courier New"]local a = ScenEdit_GetUnit({name='LST 4001 Osumi', guid='8269b881-20ce-4f2e-baa0-6823e46d55a4'})[/font]

[font="Courier New"]print(a.fields)[/font] -- shows you a list of all the property and method names associated with the wrapper (in this case the unit one)

You can use this to show a list all the properties and their current values.

[font="Courier New"]for k,v in pairs(a.fields) do
if string.find(k,'property_') ~= nil then
local t = string.find(v," , ") -- location of first ,
print("\r\n[object] = " .. string.sub(v,2,t-1) ) -- property name
print( a[string.sub(v,2,t-1)] ) -- value of property
end
end[/font]
Michael
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Dump the properties of Lua wrapper

Post by michaelm75au »

Example of output:

{ property_38 = '.condition , String , False', property_16 = '.sprintDrift , Boolean , True', property_22 = '.side , String , False', property_26 = '.airbornetime , Object , False', property_29 = '.damage , LuaTable , False', property_47 = '.targetedBy , Object , False', property_8 = '.throttle , Object , True', property_5 = '.speed , Object , True', property_15 = '.base , LuaWrapper_ActiveUnit , True', property_3 = '.autodetectable , Boolean , True', property_20 = '.name , String , True', property_4 = '.altitude , Object , True', property_14 = '.OODA , LuaTable , True', method_4 = ':inArea , System.Boolean', property_32 = '.weather , LuaTable , False', property_27 = '.readytime , Object , False', property_6 = '.manualAltitude , Object , True', property_48 = '.firingAt , Object , False', property_25 = '.holdfire , Object , True', method_3 = ':rangetotarget , System.Single', property_13 = '.heading , Object , True', property_37 = '.components , LuaTable , True', property_34 = '.magazines , LuaTable , True', property_45 = '.areaTriggersFired , LuaTable , False', method_1 = ':delete , System.Void', property_50 = '.isOperating , Boolean , False', property_49 = '.firedOn , Object , False', property_46 = '.hostedUnits , LuaTable , False', property_28 = '.loadoutdbid , Object , False', property_18 = '.type , String , False', property_2 = '.longitude , Double , True', property_44 = '.hostFacility , LuaWrapper_Facility , False', property_12 = '.formation , LuaTable , True', property_43 = '.weapon , Object , False', property_42 = '.weaponstate , String , False', property_41 = '.fuelstate , String , False', property_24 = '.holdposition , Boolean , True', property_39 = '.condition_v , String , False', property_36 = '.sensors , LuaTable , True', property_35 = '.mounts , LuaTable , True', property_33 = '.proficiency , String , True', method_2 = ':filterOnComponent , NLua.LuaTable', property_10 = '.fuel , LuaTable , True', property_23 = '.mission , Object , True', property_31 = '.desiredheading , Object , True', property_9 = '.course , LuaTable , True', property_30 = '.ascontact , LuaTable , False', property_21 = '.guid , String , False', property_40 = '.unitstate , String , False', property_1 = '.latitude , Double , True', property_7 = '.manualSpeed , Object , True', property_19 = '.dbid , Int32 , False', property_17 = '.subtype , String , False', property_11 = '.group , Object , True' }

[object] = condition
Underway
[object] = sprintDrift
'No'
[object] = side
SideA
[object] = airbornetime
nil
[object] = damage
{ dp = 1490, fires = 'NoFire', startdp = '1490', flood = 'NoFlooding' }
[object] = targetedBy
nil
[object] = throttle
FullStop
[object] = speed
0
[object] = base
nil
[object] = autodetectable
'No'
[object] = name
LST 4001 Osumi
[object] = altitude
0
[object] = OODA
{ detection = 15, evasion = 2, targeting = 15 }
[object] = weather
{ rainfall = 0, undercloud = 0, seastate = 0, temp = 25 }
[object] = readytime
0
[object] = manualAltitude
'No'
[object] = firingAt
nil
[object] = holdfire
{ Land = 'Inherit', SubSurface = 'Inherit', Air = 'Inherit', Surface = 'Inherit' }
[object] = heading
0
[object] = components
{ [1] = { comp_guid = 'e9de3642-205a-44b1-a619-4bad9877e92d', comp_name = 'J/OPS-14C', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 2994 }, [2] = { comp_guid = '33496d54-eb05-40ba-9b12-e6463246d186', comp_name = 'J/OPS-18A', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 1177 }, [3] = { comp_guid = '33e91ecc-198f-4f2f-8358-0739344fb69e', comp_name = 'J/OPS-20', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 1036 }, [4] = { comp_guid = 'd6f22747-5ad1-4ba3-b3ae-bfe9cf667c0e', comp_name = 'J/OPS-28C', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 1180 }, [5] = { comp_guid = '6ac912bc-dbf5-41ce-99dd-8037ac8ed835', comp_name = 'Mk1 Eyeball', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 0 }, [6] = { comp_guid = '1a6583ae-e225-4635-a889-dc5521516d9b', comp_name = 'AN/VPS-2 Search/Track [Mk16 CWIS]', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 1650 }, [7] = { comp_guid = 'f5008eca-ae1f-4f53-85e3-48523cd0a634', comp_name = 'AN/VPS-2 Search/Track [Mk16 CWIS]', comp_type = 'Sensor', comp_status = 'Operational', comp_dbid = 1650 }, [8] = { comp_guid = 'fa6f6e50-af94-4fc2-aefd-44c3909c8194', comp_name = '12.7mm/50 MG', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 561 }, [9] = { comp_guid = 'e791d810-b777-4050-bca1-4e9bce55c424', comp_name = '12.7mm/50 MG', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 561 }, [10] = { comp_guid = '2c0ce75a-b307-4e80-b390-ec4d26f9c654', comp_name = '20mm/85 Mk15 Phalanx Blk 1 CIWS', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 542 }, [11] = { comp_guid = '96da87de-5476-4ca5-bd4b-ea77209b80e4', comp_name = '20mm/85 Mk15 Phalanx Blk 1 CIWS', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 542 }, [12] = { comp_guid = '7b2a8bf1-b7fb-43cc-af64-97603a278621', comp_name = 'Mk36 SRBOC', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 565 }, [13] = { comp_guid = 'fbd82461-4dd8-4106-a7a8-0cc973f690a5', comp_name = 'Mk36 SRBOC', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 565 }, [14] = { comp_guid = '6abdae96-0168-49cc-b553-d0a02f413e70', comp_name = 'Mk36 SRBOC', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 565 }, [15] = { comp_guid = '6a97dfbb-ff0c-4db9-8825-7d6ccf007b7a', comp_name = 'Mk36 SRBOC', comp_type = 'Mount', comp_status = 'Operational', comp_dbid = 565 }, [16] = { comp_guid = 'dfa22829-693a-4239-bb97-c91f90d263d4', comp_name = 'VHF Radio [Secure]', comp_type = 'CommDevice', comp_status = 'Operational', comp_dbid = 209 }, [17] = { comp_guid = '0faf4083-b3ef-4b0d-9887-9d1eabeb61f2', comp_name = 'AN/WSC-3 FLTSATCOM SHF Shipboard Transceiver', comp_type = 'CommDevice', comp_status = 'Operational', comp_dbid = 218 }, [18] = { comp_guid = 'a227de13-de1b-4bb3-baa3-af1164d9961e', comp_name = 'Link 14', comp_type = 'CommDevice', comp_status = 'Operational', comp_dbid = 219 }, [19] = { comp_guid = '09f88b30-e00f-4745-9c09-fe65bcfdfbb4', comp_name = 'MILSTAR SATCOM UHF', comp_type = 'CommDevice', comp_status = 'Operational', comp_dbid = 222 }, [20] = { comp_guid = 'b7c2067f-0c0a-478d-ac73-d20e550434c1', comp_name = 'UHF Radio [Secure]', comp_type = 'CommDevice', comp_status = 'Operational', comp_dbid = 264 }, [21] = { comp_guid = '2babbe24-0ebb-4413-ba54-4245a8ba9f6a', comp_name = 'Dock Well (2x Large Dock (LCU/LCAC, 25.1-45m Long))', comp_type = 'DockFacility', comp_status = 'Operational', comp_dbid = 7 }, [22] = { comp_guid = '317d2e0b-0fa2-4e62-bf82-d4195b71c7c6', comp_name = 'Pad (1x Medium Aircraft (12.1-18m Long))', comp_type = 'AirFacility', comp_status = 'Operational', comp_dbid = 57 }, [23] = { comp_guid = '4debec89-b073-4895-b990-03b15d247c98', comp_name = 'Pad (1x Medium Aircraft (12.1-18m Long))', comp_type = 'AirFacility', comp_status = 'Operational', comp_dbid = 57 }, [24] = { comp_guid = '74147cfb-df6b-4053-b275-9486962e8b12', comp_name = 'Open Parking (2x Medium Aircraft (12.1-18m Long))', comp_type = 'AirFacility', comp_status = 'Operational', comp_dbid = 21 }, [25] = { comp_guid = '8b7d836e-9944-4e0f-bfb1-b17c4f1a5b1f', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [26] = { comp_guid = '306a04a2-4145-46c0-b4a6-3af2815b8644', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [27] = { comp_guid = '449d3053-4c3c-4bfd-8fd2-eb65384a5beb', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [28] = { comp_guid = '2604a87d-f855-4ad4-a5f6-a724f301d4e1', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [29] = { comp_guid = '12459b2c-ebaf-4229-91fa-c9c1f80109e6', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [30] = { comp_guid = 'd929ad86-ffa8-4a62-ace3-f0f3c5d93542', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [31] = { comp_guid = 'd640be95-95e6-4ead-aa42-cc5d52ecc1c9', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [32] = { comp_guid = '5888bf98-876d-418d-ad24-1ae8a78d5e59', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [33] = { comp_guid = '2b46cb02-5a86-4171-bc0b-e34cfbab295d', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [34] = { comp_guid = '53e86349-967c-479f-920a-2f6bb5a0f33d', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [35] = { comp_guid = 'a8f565d1-79d5-46f8-8da4-6eccdf4d3597', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [36] = { comp_guid = 'e876e161-d77c-4648-8f6f-05a08e01967b', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [37] = { comp_guid = '671a9039-707f-4052-9069-544637b5e467', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [38] = { comp_guid = 'f782e200-4b13-4952-81a5-97901c97aff0', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [39] = { comp_guid = '0bfbc39b-7a74-4057-acae-4261fc37c6b4', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [40] = { comp_guid = '2bc6f08c-e732-49e6-a8de-dc57f0632942', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [41] = { comp_guid = 'a04daaf5-e001-4686-a403-b35ff6c4f23c', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [42] = { comp_guid = 'eb8636fa-315e-44cb-bf61-fdcbdfffab5d', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [43] = { comp_guid = '6a2b25a4-93e3-4462-9fc2-9ba9d2423210', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [44] = { comp_guid = 'b518d1f7-b54f-47bc-ad50-500f096cf253', comp_name = 'Infantry Section [7.62mm MG/Unguided Infantry Anti Tank Weapon]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2884 }, [45] = { comp_guid = 'e68dfee9-c7eb-42e7-a64a-fcc04f9a9691', comp_name = '81mm Mortar', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 132 }, [46] = { comp_guid = 'b3936b09-77a5-47c0-8072-d603fa0f3960', comp_name = '81mm Mortar', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 132 }, [47] = { comp_guid = '547d146a-b5d3-4b33-894d-5fdd21fcf49b', comp_name = '81mm Mortar', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 132 }, [48] = { comp_guid = '89277140-b477-4efa-9d92-f97f0d3cc457', comp_name = '81mm Mortar', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 132 }, [49] = { comp_guid = '609b792b-8562-445d-9fa3-518b8bd95a7e', comp_name = '81mm Mortar', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 132 }, [50] = { comp_guid = 'd01ad060-0ac8-4c2a-a34b-0ab17f9097f7', comp_name = '81mm Mortar', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 132 }, [51] = { comp_guid = '4581abea-35d3-439a-80a8-2ec7d05a2dc5', comp_name = 'LAV-25 [25mm/75 M242 Bushmaster]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2234 }, [52] = { comp_guid = '82180f9d-d19d-4718-a482-ca4a56878b9e', comp_name = 'LAV-25 [25mm/75 M242 Bushmaster]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2234 }, [53] = { comp_guid = '0da09656-7b52-41eb-8f7e-e5cea70e040e', comp_name = 'LAV-25 [25mm/75 M242 Bushmaster]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2234 }, [54] = { comp_guid = 'c972511d-7659-4882-8b8a-d777b4cb30ea', comp_name = 'LAV-25 [25mm/75 M242 Bushmaster]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2234 }, [55] = { comp_guid = 'ddfef949-26fc-4f81-bb9f-ebb22fe456b5', comp_name = 'LAV-25 [25mm/75 M242 Bushmaster]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2234 }, [56] = { comp_guid = '9962a277-4f6c-4666-8f54-fb3ec534b03a', comp_name = 'LAV-25 [25mm/75 M242 Bushmaster]', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 2234 }, [57] = { comp_guid = '8f17fbae-2fb5-4b7f-a57a-12af0d2a9aa7', comp_name = 'M1A2 Abrams Main Battle Tank', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 754 }, [58] = { comp_guid = '47fdfb43-7eaf-46be-bc3d-4e5b49574482', comp_name = 'M1A2 Abrams Main Battle Tank', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 754 }, [59] = { comp_guid = 'f8a74463-8833-4514-8c00-73a42c7210c8', comp_name = 'M1A2 Abrams Main Battle Tank', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 754 }, [60] = { comp_guid = '99227e14-e3b1-4c54-afb9-fdb26eafe408', comp_name = 'M1A2 Abrams Main Battle Tank', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 754 }, [61] = { comp_guid = 'b2073e15-77e3-4335-88b6-152a46095fc7', comp_name = 'M1A2 Abrams Main Battle Tank', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 754 }, [62] = { comp_guid = 'd9b062be-a7f3-4c22-b346-aa49c8a8cdf0', comp_name = 'M1A2 Abrams Main Battle Tank', comp_type = 'Cargo', comp_status = 'Operational', comp_dbid = 754 }, [63] = { comp_guid = 'b584aba1-2ebc-43b1-84cf-a9abc3c96b8c', comp_name = '2x Mitsui-SEMT-Pielstick 16V42M-A Diesels', comp_type = 'Engine', comp_status = 'Operational', comp_dbid = 1026 }, [64] = { comp_guid = '59d07524-47be-4663-b5ae-b34911b42238', comp_name = '12.7mm/50 MG', comp_type = 'Magazine', comp_status = 'Operational', comp_dbid = 761 }, [65] = { comp_guid = '194ad06a-6a60-41a1-95e0-b93140a0ab55', comp_name = '20mm/85 Mk15 Phalanx Blk 1', comp_type = 'Magazine', comp_status = 'Operational', comp_dbid = 545 }, [66] = { comp_guid = '90bdecb4-b294-47a2-8141-79395965b53c', comp_name = 'Helicopter Magazine', comp_type = 'Magazine', comp_status = 'Operational', comp_dbid = 1302 }, [67] = { comp_guid = 'd97c16d2-b895-4a61-b7b7-0588c854b5fb', comp_name = 'Mk36 SRBOC', comp_type = 'Magazine', comp_status = 'Operational', comp_dbid = 597 } }
[object] = magazines
{ [1] = { mag_weapons = { [1] = { wpn_guid = '8c12a4a9-731d-4cf3-9b84-5f0b896cfd1d', wpn_maxcap = 200, wpn_default = 200, wpn_dbid = 1695, wpn_name = '12.7mm/50 MG Burst [10 rnds]', wpn_current = 200 } }, mag_name = '12.7mm/50 MG', mag_dbid = 761, mag_guid = '59d07524-47be-4663-b5ae-b34911b42238', mag_capacity = 200 }, [2] = { mag_weapons = { [1] = { wpn_guid = 'e9f3a062-b893-4d3b-98ac-db64c568f68e', wpn_maxcap = 20, wpn_default = 20, wpn_dbid = 1630, wpn_name = '20mm/85 Mk15 Phalanx Blk 1 Burst [300 rnds]', wpn_current = 20 } }, mag_name = '20mm/85 Mk15 Phalanx Blk 1', mag_dbid = 545, mag_guid = '194ad06a-6a60-41a1-95e0-b93140a0ab55', mag_capacity = 20 }, [3] = { mag_weapons = { [1] = { wpn_guid = '8674170e-fe67-4c6f-913d-8ce28d614d61', wpn_maxcap = 24, wpn_default = 24, wpn_dbid = 617, wpn_name = 'AGM-114M Hellfire II', wpn_current = 24 }, [2] = { wpn_guid = '3477a79c-0240-4165-998f-bcfd2bef992d', wpn_maxcap = 40, wpn_default = 40, wpn_dbid = 1647, wpn_name = 'Mk46 NEARTIP Mod 5', wpn_current = 40 } }, mag_name = 'Helicopter Magazine', mag_dbid = 1302, mag_guid = '90bdecb4-b294-47a2-8141-79395965b53c', mag_capacity = 10000 }, [4] = { mag_weapons = { [1] = { wpn_guid = '2a99c0b4-724b-46bb-8a2e-3e5d70c785e7', wpn_maxcap = 80, wpn_default = 64, wpn_dbid = 232, wpn_name = 'Mk182 SRBOC Chaff [Seduction]', wpn_current = 64 }, [2] = { wpn_guid = '5e5af0e1-3cf6-4d09-a228-7c688af61605', wpn_maxcap = 80, wpn_default = 16, wpn_dbid = 233, wpn_name = 'Mk186 TORCH Flare [Seduction]', wpn_current = 16 } }, mag_name = 'Mk36 SRBOC', mag_dbid = 597, mag_guid = 'd97c16d2-b895-4a61-b7b7-0588c854b5fb', mag_capacity = 80 } }
[object] = areaTriggersFired
{ }
[object] = isOperating
'Yes'
[object] = firedOn
nil
[object] = hostedUnits
{ Boats = { [1] = '2e324031-e62c-4bb7-8351-cba87d1d867e', [2] = '0bbdc89f-3312-418e-b130-d835a9a8fbec', [3] = '3544790b-19ef-464e-9a77-a2d48f851495', [4] = '7bd658f0-83b5-4e85-8431-a4b6101a1802', 4 = '7bd658f0-83b5-4e85-8431-a4b6101a1802', 1 = '2e324031-e62c-4bb7-8351-cba87d1d867e', 2 = '0bbdc89f-3312-418e-b130-d835a9a8fbec', 3 = '3544790b-19ef-464e-9a77-a2d48f851495' }, Aircraft = { [1] = '7a3b7dce-abe1-4b60-b0d5-b0f27510d4de', [2] = 'e7bb5afe-033d-4f9f-a248-067484d6168c', 2 = 'e7bb5afe-033d-4f9f-a248-067484d6168c', 1 = '7a3b7dce-abe1-4b60-b0d5-b0f27510d4de' } }
[object] = loadoutdbid
nil
[object] = type
Ship
[object] = longitude
137.655665231357
[object] = hostFacility
nil
[object] = formation
nil
[object] = weapon
nil
[object] = weaponstate
None
[object] = fuelstate
None
[object] = holdposition
'No'
[object] = condition_v
Underway
[object] = sensors
{ [1] = { sensor_isactive = 'No', sensor_type = 2001, sensor_guid = 'e9de3642-205a-44b1-a619-4bad9877e92d', sensor_maxrange = 120, sensor_dbid = 2994, sensor_status = 'Operational', sensor_name = 'J/OPS-14C', sensor_role = 2003 }, [2] = { sensor_isactive = 'No', sensor_type = 2001, sensor_guid = '33496d54-eb05-40ba-9b12-e6463246d186', sensor_maxrange = 40, sensor_dbid = 1177, sensor_status = 'Operational', sensor_name = 'J/OPS-18A', sensor_role = 2023 }, [3] = { sensor_isactive = 'No', sensor_type = 2001, sensor_guid = '33e91ecc-198f-4f2f-8358-0739344fb69e', sensor_maxrange = 25, sensor_dbid = 1036, sensor_status = 'Operational', sensor_name = 'J/OPS-20', sensor_role = 2028 }, [4] = { sensor_isactive = 'No', sensor_type = 2001, sensor_guid = 'd6f22747-5ad1-4ba3-b3ae-bfe9cf667c0e', sensor_maxrange = 110, sensor_dbid = 1180, sensor_status = 'Operational', sensor_name = 'J/OPS-28C', sensor_role = 2103 }, [5] = { sensor_isactive = 'No', sensor_type = 2003, sensor_guid = '6ac912bc-dbf5-41ce-99dd-8037ac8ed835', sensor_maxrange = 50, sensor_dbid = 0, sensor_status = 'Operational', sensor_name = 'Mk1 Eyeball', sensor_role = 2016 }, [6] = { sensor_isactive = 'No', sensor_type = 2001, sensor_guid = '1a6583ae-e225-4635-a889-dc5521516d9b', sensor_maxrange = 2.70000004768372, sensor_dbid = 1650, sensor_status = 'Operational', sensor_name = 'AN/VPS-2 Search/Track [Mk16 CWIS]', sensor_role = 2133 }, [7] = { sensor_isactive = 'No', sensor_type = 2001, sensor_guid = 'f5008eca-ae1f-4f53-85e3-48523cd0a634', sensor_maxrange = 2.70000004768372, sensor_dbid = 1650, sensor_status = 'Operational', sensor_name = 'AN/VPS-2 Search/Track [Mk16 CWIS]', sensor_role = 2133 } }
[object] = mounts
{ [1] = { mount_guid = 'fa6f6e50-af94-4fc2-aefd-44c3909c8194', mount_name = '12.7mm/50 MG', mount_status = 'Operational', mount_dbid = 561, mount_weapons = { [1] = { wpn_guid = 'fcdfe056-8502-46bf-aac5-c4a854605aa7', wpn_maxcap = 10, wpn_default = 10, wpn_dbid = 1695, wpn_current = 10, wpn_name = '12.7mm/50 MG Burst [10 rnds]', wpn_type = 2004 } } }, [2] = { mount_guid = 'e791d810-b777-4050-bca1-4e9bce55c424', mount_name = '12.7mm/50 MG', mount_status = 'Operational', mount_dbid = 561, mount_weapons = { [1] = { wpn_guid = 'c421783c-3d75-423b-a1f9-4c49a21fbae7', wpn_maxcap = 10, wpn_default = 10, wpn_dbid = 1695, wpn_current = 10, wpn_name = '12.7mm/50 MG Burst [10 rnds]', wpn_type = 2004 } } }, [3] = { mount_guid = '2c0ce75a-b307-4e80-b390-ec4d26f9c654', mount_name = '20mm/85 Mk15 Phalanx Blk 1 CIWS', mount_status = 'Operational', mount_dbid = 542, mount_weapons = { [1] = { wpn_guid = '3cf06dbb-ce3d-4901-b06a-f338a9dd2c38', wpn_maxcap = 5, wpn_default = 5, wpn_dbid = 1630, wpn_current = 5, wpn_name = '20mm/85 Mk15 Phalanx Blk 1 Burst [300 rnds]', wpn_type = 2004 } } }, [4] = { mount_guid = '96da87de-5476-4ca5-bd4b-ea77209b80e4', mount_name = '20mm/85 Mk15 Phalanx Blk 1 CIWS', mount_status = 'Operational', mount_dbid = 542, mount_weapons = { [1] = { wpn_guid = '6f22aa0a-d433-41dd-a622-421022c7d2ba', wpn_maxcap = 5, wpn_default = 5, wpn_dbid = 1630, wpn_current = 5, wpn_name = '20mm/85 Mk15 Phalanx Blk 1 Burst [300 rnds]', wpn_type = 2004 } } }, [5] = { mount_guid = '7b2a8bf1-b7fb-43cc-af64-97603a278621', mount_name = 'Mk36 SRBOC', mount_status = 'Operational', mount_dbid = 565, mount_weapons = { [1] = { wpn_guid = '495854aa-5ecc-4f56-8c77-268a848f63ac', wpn_maxcap = 6, wpn_default = 4, wpn_dbid = 232, wpn_current = 4, wpn_name = 'Mk182 SRBOC Chaff [Seduction]', wpn_type = 2005 }, [2] = { wpn_guid = '0a42d61b-3825-4011-a820-6b1175272457', wpn_maxcap = 6, wpn_default = 2, wpn_dbid = 233, wpn_current = 2, wpn_name = 'Mk186 TORCH Flare [Seduction]', wpn_type = 2005 } } }, [6] = { mount_guid = 'fbd82461-4dd8-4106-a7a8-0cc973f690a5', mount_name = 'Mk36 SRBOC', mount_status = 'Operational', mount_dbid = 565, mount_weapons = { [1] = { wpn_guid = 'ed8bc25a-f872-4dfa-87bc-4ad2517ec04a', wpn_maxcap = 6, wpn_default = 4, wpn_dbid = 232, wpn_current = 4, wpn_name = 'Mk182 SRBOC Chaff [Seduction]', wpn_type = 2005 }, [2] = { wpn_guid = 'a1cd8e44-5141-4b07-b3bd-d3deb5cef874', wpn_maxcap = 6, wpn_default = 2, wpn_dbid = 233, wpn_current = 2, wpn_name = 'Mk186 TORCH Flare [Seduction]', wpn_type = 2005 } } }, [7] = { mount_guid = '6abdae96-0168-49cc-b553-d0a02f413e70', mount_name = 'Mk36 SRBOC', mount_status = 'Operational', mount_dbid = 565, mount_weapons = { [1] = { wpn_guid = '37cec8ce-8e07-4943-899e-c880a8b74962', wpn_maxcap = 6, wpn_default = 4, wpn_dbid = 232, wpn_current = 4, wpn_name = 'Mk182 SRBOC Chaff [Seduction]', wpn_type = 2005 }, [2] = { wpn_guid = '19d319f8-8315-4fb0-a890-1609e79876f1', wpn_maxcap = 6, wpn_default = 2, wpn_dbid = 233, wpn_current = 2, wpn_name = 'Mk186 TORCH Flare [Seduction]', wpn_type = 2005 } } }, [8] = { mount_guid = '6a97dfbb-ff0c-4db9-8825-7d6ccf007b7a', mount_name = 'Mk36 SRBOC', mount_status = 'Operational', mount_dbid = 565, mount_weapons = { [1] = { wpn_guid = '2f54b5da-3cee-42db-a8c8-926a1b8761b5', wpn_maxcap = 6, wpn_default = 4, wpn_dbid = 232, wpn_current = 4, wpn_name = 'Mk182 SRBOC Chaff [Seduction]', wpn_type = 2005 }, [2] = { wpn_guid = '920c0c15-e53b-4126-8567-330cd01834f6', wpn_maxcap = 6, wpn_default = 2, wpn_dbid = 233, wpn_current = 2, wpn_name = 'Mk186 TORCH Flare [Seduction]', wpn_type = 2005 } } } }
[object] = proficiency
Regular
[object] = fuel
{ [3001] = { name = 'DieselFuel', max = 26667, current = 26667 } }
[object] = mission
nil
[object] = desiredheading
0
[object] = course
{ }
[object] = ascontact
{ }
[object] = guid
8269b881-20ce-4f2e-baa0-6823e46d55a4
[object] = unitstate
Unassigned
[object] = latitude
34.0930076804559
[object] = manualSpeed
nil
[object] = dbid
961
[object] = subtype
4013
[object] = group
nil
Michael
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Dump the properties of Lua wrapper

Post by Whicker »

Thanks - I had seen something about this, maybe on commandlua but I didn't quite understand what it was getting at - this is a clear example and shows exactly what it is.

Also, nice example with an LST loaded with boats and cargo.
User avatar
kevinkins
Posts: 2465
Joined: Wed Mar 08, 2006 11:54 am

RE: Dump the properties of Lua wrapper

Post by kevinkins »

What is meant by a "wrapper" from a programming POV?

Kevin
“The study of history lies at the foundation of all sound military conclusions and practice.”
Alfred Thayer Mahan
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Dump the properties of Lua wrapper

Post by tjhkkr »

michaelm75au:

Is there a way to dump this to a text file?
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Dump the properties of Lua wrapper

Post by Whicker »

I'm no Lua expert, but to me the `wrapper` is just the container for something like a unit which has tons of possible attributes/properties. In the game a unit is a living thing that has lots of things pertaining to it - like within that wrapper (for a unit) could be things like damage, which is its own table of items, or cargo, or weapons etc. I kinda think of it as an object, though I think that is technically incorrect and refers to something similar in other languages like JS.
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Dump the properties of Lua wrapper

Post by Whicker »

as for writing that to a text file, if you run that (or anything) in the lua console it is already in a txt file - the LuaHistory_[date].txt file found in /logs. Should be easy to find it in there and paste it into its own doc. or just copy it from the lua console into its own file.

The lua language supports writing to a file but I tried to do that and it didn't work (no surprise, I don't really know what I am doing). Maybe cmano-lua didn't include the io library.
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Dump the properties of Lua wrapper

Post by stilesw »

Hi all.

Just an FYI FWIF (don't you just love acronyms). I would compare the "wrapper" to a "structure" found in other programming languages such as C/C++.

Specifically, "Structure is a collection of variables of different types under a single name." (https://www.programiz.com/c-programming/c-structures).

Probably more information than most forum members are interested in.

-Wayne Stiles
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
User avatar
tjhkkr
Posts: 2431
Joined: Wed Jun 02, 2010 11:15 pm
Contact:

RE: Dump the properties of Lua wrapper

Post by tjhkkr »

ORIGINAL: stilesw
Hi all.
Just an FYI FWIF (don't you just love acronyms).
-Wayne Stiles

I say this in fun:
No, because I do not know what FWIF means!
[:D]
Remember that the evil which is now in the world will become yet more powerful, and that it is not evil which conquers evil, but only love -- Olga Romanov.
User avatar
stilesw
Posts: 1572
Joined: Wed Jun 25, 2014 10:08 pm
Location: Hansville, WA, USA

RE: Dump the properties of Lua wrapper

Post by stilesw »

Once again I prove that I cannot spell - even acronyms. Sigh!

FWIF should be (obviously) FWIW (For What It's Worth).

Thanks for the catch.

-Wayne
“There is no limit to what a man can do so long as he does not care a straw who gets the credit for it.”

Charles Edward Montague, English novelist and essayist
~Disenchantment, ch. 15 (1922)
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Dump the properties of Lua wrapper

Post by Whicker »

another version of how to get all of a units properties.
video explanation:
https://www.youtube.com/watch?v=F5eVMhro9kY

-----------------------------------------------------------------------------
local u = ScenEdit_GetUnit({name='LPD 17 San Antonio', guid='63917afb-6cdb-47b5-9f2a-ffd3e9e86224'})
local tables = {}
for k,v in pairs(u.fields) do
local t = string.find(v," , ")
local t2 = (string.sub(v,2,t-1))
if type(u[t2]) ~= 'table' then
print(t2..': '..tostring(u[t2]))
else
table.insert(tables, t2)
end --end check type

end -- end main pairs loop

print'==================== Table Data ======================'
for k,v in pairs(tables) do
print(v..': ')
for k,v in pairs(u[v]) do
print(k)
print(v)
end --inner table

print('---------- End '..v..' table data ------------------')
print('----------------------------------------------------')
end --end tables loop
Whicker
Posts: 664
Joined: Tue Jun 19, 2018 9:54 pm

RE: Dump the properties of Lua wrapper

Post by Whicker »

when you run this now there is an error on a new field called Launch - and if I just do print(u.Launch) I get an error:ERROR: [string "local function index(obj,name)
..."]:7: unknown member name Launch

I get that error on both my script above and the one by Michael at the top.

I'm guessing Launch is the new way to use lua to launch a unit? I noticed this a few weeks ago but didn't pay any attention.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Dump the properties of Lua wrapper

Post by michaelm75au »

I'll have a look.
Michael
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

RE: Dump the properties of Lua wrapper

Post by michaelm75au »

The properties Launch and RTB don't have values. They are write-only properties that set flags to force launching and RTBing. May need to to ignore these properties when building table property values.
-------------------
Actually better to add as method instead of a property.
Michael
User avatar
1nutworld
Posts: 418
Joined: Sun Apr 13, 2014 12:34 pm

RE: Dump the properties of Lua wrapper

Post by 1nutworld »

ORIGINAL: stilesw

Once again I prove that I cannot spell - even acronyms. Sigh!

FWIF should be (obviously) FWIW (For What It's Worth).

Thanks for the catch.

-Wayne

For what it's worth, even though the acronym was spelled incorrectly - I didn't notice it, and READ it as

FWIW!

Maybe that helps some?? [:D]
USS Dwight D. Eisenhower (CVN-69) 1990-1994.
User avatar
wqc12345
Posts: 176
Joined: Mon Dec 07, 2015 2:56 pm
Location: San Francisco, CA

RE: Dump the properties of Lua wrapper

Post by wqc12345 »

Getting a crash with this on [object] = base
ERROR: Object reference not set to an instance of an object.

This is for a an aircraft dump.
genzil
Posts: 1
Joined: Fri Jun 10, 2022 4:49 pm

Re: Dump the properties of Lua wrapper

Post by genzil »

I am a newcomer and I am trying to get the detail of a record in the LUA console.
As a data source I am using the scenario 'Uncle Mark's Tutorials - 1 - NATO Surface Group vs. Soviet Forces, 1985'.

Using something very similar to the initial code presented in this post:

Code: Select all

  for k,v in pairs(obj.fields) do
      if (string.find(k, 'property_') ~= nil) then
          -- property name and value
          local t = string.find(v, ' , ') -- location of first
          local name = string.sub(v, 2, t-1)
          local value = obj[name]

          print('  ' .. name .. ': ' .. type(value))
      end
  end
I get for the 'Exeter Surface Group' the following result (trimmed to reduce the size of this post :):

-> a = ScenEdit_GetUnit({name='Exeter Surface Group'})

fuels: table
autodetectable: boolean
side: string
throttle: userdata
proficiency: string
unassign: userdata
classname: string
targetedBy: nil
OODA: table
IsUnguidedBallisticWeapon: boolean
weather: table
...
group: userdata
heading: number
...

So far so good, the idea is to iterate recursively to get all the fields.
If the field is a table, then I can loop 'for k,v in pairs(<table field>) ...' to retrieve each of their fields, but if it's a 'userdata', then I thought I could use '<obj>.fields' again to retrieve each property of the structure, which works in general, for example for the 'group' field it delivers:

unitlist: table
type: string
lead: string
side: string
guid: string
name: string

But I encountered some errors. At the beginning you can't access 'fields' of any userdata:

-> print(type(a.throttle))
userdata
-> print(a.throttle)
Cruise
-> print(throttle.fields)
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
...

But also:

-> print(type(a.unassign))
userdata
-> print(a.unassign)
NLua.Exceptions.LuaScriptException: [string "?"]:1: Unknown member name unassign
-> print(a.unassign.fields)
KeraLua.LuaFunction

I obviously don't understand enough what 'userdata' means, but I would like to be able to iterate recursively (without errors that stop the script) on an object to retrieve all its fields. Is there any way to do that?

Thanks for any help you can give me.
User avatar
michaelm75au
Posts: 12457
Joined: Sat May 05, 2001 8:00 am
Location: Melbourne, Australia

Re: Dump the properties of Lua wrapper

Post by michaelm75au »

-> print(throttle.fields)
The property 'fields' only applies to the wrapper object itself, and not the fields under it.
-> print(a.unassign)
NLua.Exceptions.LuaScriptException: [string "?"]:1: Unknown member name unassign
-> print(a.unassign.fields)
KeraLua.LuaFunction
There are 2 fields (unassign and oldDamagePercent) that don't have read access (unknown member). I came across that myself yesterday. I have made changes to allow these to be ignored in future.
This is how those can be ignored in future.

Code: Select all

for k,v in pairs(a.fields) do
 if string.find(k,'property_') ~= nil then -- is a property
  --print("\r\n" .. v)
  local vt = {}
  local i = 0
  for w in string.gmatch(v,'%g+[^, ]') do  -- property breakdown - name, Lua type, writable, readable
    vt[i] = w
    --print(vt[i])
    i=i+1
  end

  print("\r\n[object] = " .. string.sub(vt[0],2) ) -- property name
  if vt[3] == 'True' then
    print( a[ string.sub(vt[0],2) ] ) -- value of property
  else
    print( 'no get function' ) -- property can't be accessed
  end
 end
end
'userdata' refers to the data that doesn't fit into Lua's known types. For 'throttle', it is a C ENUM type which is basically a number to string representation depending on how it is used. For 'group', it is referencing another unit wrapper
Michael
Parel803
Posts: 937
Joined: Thu Oct 10, 2019 3:39 pm
Location: Netherlands

Re: Dump the properties of Lua wrapper

Post by Parel803 »

Good afternoon,
Just FYI I got this at the last 3 of 24 objects
[object] = airbornetime_v
nil

[object] = groundSpeed
0

[object] = unassign
ERROR: [string "?"]:1: Unknown member name unassign

Realizing I'm prob doing something wrong.

best regards GJ
Post Reply

Return to “Lua Legion”