HELP! Convert String to Table - Run Lua Functions from server

I am developing an app that receives information in Lua from a server via TCP as a string, and I would like to convert it to a Lua table and run functions from that table in my app. Here is an example of the Lua table coming from the server as a string.

return {msg_type=7, chunk=[===[user_call_back([=[{{{dir_name=[[Maintenance]]},{{ui_description=[[MPT Studio (compiled)]],put_name=[[MPT2 Instrument Verification]],put_file_utf8=[[db\tests\products\tools\MPT Instrument Verification\MPT2 Instrument Verification.mpt_productc]],avail_env={testing=1},put_file=[[ZGJcdGVzdHNccHJvZHVjdHNcdG9vbHNcTVBUIEluc3RydW1lbnQgVmVyaWZpY2F0aW9uXE1QVDIgSW5zdHJ1bWVudCBWZXJpZmljYXRpb24ubXB0X3Byb2R1Y3Rj]],put_file2=[[tools\MPT Instrument Verification\MPT2 Instrument Verification]],put_file_org=[[db\tests\products\tools\MPT Instrument Verification\MPT2 Instrument Verification.mpt_productc]]},dir_name=[[MPT Instrument Verification]]},dir_name=[[tools]]},{ui_description=[[MPT Studio]],put_name=[[mpt-remote-api]],put_file_utf8=[[db\tests\products\mpt-remote-api.mpt_product]],avail_env={testing=1},put_file=[==[ZGJcdGVzdHNccHJvZHVjdHNcbXB0LXJlbW90ZS1hcGkubXB0X3Byb2R1Y3Q=]==],put_file2=[[mpt-remote-api]],put_file_org=[[db\tests\products\mpt-remote-api.mpt_product]]},{ui_description=[[MPT Studio]],put_name=[[resistance kelvin]],put_file_utf8=[[db\tests\products\resistance kelvin.mpt_product]],avail_env={testing=1},put_file=[==[ZGJcdGVzdHNccHJvZHVjdHNccmVzaXN0YW5jZSBrZWx2aW4ubXB0X3Byb2R1Y3Q=]==],put_file2=[[resistance kelvin]],put_file_org=[[db\tests\products\resistance kelvin.mpt_product]]}}]=])]===]}

I want to extract all the file names under the put_name= category and put them in a list in a dialog box. Would the best approach be to convert the string to a table or to use string parsing tools like string.find? Would be greatly appreciated. Thank you!

Since the string you receive is NOT in a lua-table-string format or a valid json-table-string, then converting it to a table-string will be a good solution in case you use ALL data of it. It is (processor)-time consuming, but you need only selected fields. So, keep it simple! Do only the job required. So, string.find will be a reasonable choice.

local mpt_str = "your long string"

pos_start_int, pos_end_int = string.find(mpt_str, "put_name=")
if pos_start_int == nil then
	pos_start_int = 0
end

while pos_start_int > 0 do
	a_length_int = string.len(mpt_str)
	pos_end_int = pos_end_int + 3 -- we cannot use "[" in .find
	-- as it is taken as a part of pattern
	mpt_str = string.sub(mpt_str, pos_end_int, a_length_int)
	pos_start_int, pos_end_int = string.find(mpt_str, "put_name=")
	if pos_start_int == nil then
		pos_start_int = 0
	end
	end_pos_int = string.find(mpt_str, "]") - 1
	file_name_str = string.sub(mpt_str, 1, end_pos_int)
	print(file_name_str)
end

P.S. It could have been a different and easier scenario if the server really returned a string in a lua-table-string/json format.