ETP_Global_Data_Stash = {}

function ETP_StashSEXP_Stash(table_name,field_name, value)
	if ETP_Global_Data_Stash[table_name] == nil then
		ETP_Global_Data_Stash[table_name] = {}
	end
	ETP_Global_Data_Stash[table_name][field_name] = value
end

function ETP_StashSEXP_Unstash(table_name,field_name)
	if ETP_Global_Data_Stash[table_name] == nil then
		return nil
	end
	if ETP_Global_Data_Stash[table_name][field_name] == nil then
		return nil
	end
	return ETP_Global_Data_Stash[table_name][field_name]
end

mn.LuaSEXPs["data-stash-number"].Action = function (table_name,field_name,value)
	ETP_StashSEXP_Stash(table_name,field_name,value)
end

mn.LuaSEXPs["data-unstash-number"].Action = function (table_name,field_name,default)
	r = ETP_StashSEXP_Unstash(table_name,field_name,value)
	if r == nil then 
		return default
	end
	if type(r) ~= "number" then
		--do some error thing
		return default
	end
	return r
end

mn.LuaSEXPs["data-stash-number-by-shipname"].Action = function (ship,field_name,value,trim)
	table_name = ""
	if trim == true then
		table_name = ship.DisplayName
	else
		table_name = ship.Name
	end

	ETP_StashSEXP_Stash(table_name,field_name,value)
end

mn.LuaSEXPs["data-unstash-number-by-shipname"].Action = function (ship,field_name,default,trim)

	table_name = ""
	if trim == true then
		table_name = ship.DisplayName
	else
		table_name = ship.Name
	end
	r = ETP_StashSEXP_Unstash(table_name,field_name,value)
	if r == nil then 
		return default
	end
	if type(r) ~= "number" then
		--do some error thing
		return default
	end
	return r
end

mn.LuaSEXPs["data-stash-string"].Action = function (table_name,field_name,value)
	ETP_StashSEXP_Stash(table_name,field_name,value)
end

mn.LuaSEXPs["data-unstash-string"].Action = function (table_name,field_name,var)
	r = ETP_StashSEXP_Unstash(table_name,field_name,value)
	if r == nil then 
		return 
	end
	if type(r) ~= "string" then
		--do some error thing
		return
	end
	var.Value = r
end

mn.LuaSEXPs["data-stash-string-by-shipname"].Action = function (ship,field_name,value,trim)

	table_name = ""
	if trim == true then
		table_name = ship.DisplayName
	else
		table_name = ship.Name
	end

	ETP_StashSEXP_Stash(table_name,field_name,value)
end

mn.LuaSEXPs["data-unstash-string-by-shipname"].Action = function (ship,field_name,var,trim)

	table_name = ""
	if trim == true then
		table_name = ship.DisplayName
	else
		table_name = ship.Name
	end
	r = ETP_StashSEXP_Unstash(table_name,field_name,value)
	if r == nil then 
		return
	end
	if type(r) ~= "string" then
		--do some error thing
		return
	end
	var.Value = r
end


mn.LuaSEXPs["data-stash-bool"].Action = function (table_name,field_name,value)
	ETP_StashSEXP_Stash(table_name,field_name,value)
end

mn.LuaSEXPs["data-unstash-bool"].Action = function (table_name,field_name,default)
	r = ETP_StashSEXP_Unstash(table_name,field_name,value)
	if r == nil then 
		return default
	end
	if type(r) ~= "boolean" then
		--do some error thing
		return default
	end
	return r
end

mn.LuaSEXPs["data-stash-bool-by-shipname"].Action = function (ship,field_name,value,trim)
	table_name = ""
	if trim == true then
		table_name = ship.DisplayName
	else
		table_name = ship.Name
	end

	ETP_StashSEXP_Stash(table_name,field_name,value)
end

mn.LuaSEXPs["data-unstash-bool-by-shipname"].Action = function (ship,field_name,default,trim)

	table_name = ""
	if trim == true then
		table_name = ship.DisplayName
	else
		table_name = ship.Name
	end
	r = ETP_StashSEXP_Unstash(table_name,field_name,value)
	if r == nil then 
		return default
	end
	if type(r) ~= "boolean" then
		--do some error thing
		return default
	end
	return r
end