function trace(){//输出所有内容
var l=argument_count
show_debug_message("")
show_debug_message("================")
show_debug_message("trace :"+string(current_time)+": ms")
show_debug_message(" -------------- ")
for(var i=0;i<l;i++){
show_debug_message(argument[i])
}
show_debug_message("================")
show_debug_message("")
}
function format(){//格式化文本 format("{}a{}b{}c",$1,$2,$3)
var text = argument[0];
var escape_open_brace_suffix = "|"; // Suffix open brace escape character (e.g. "{|hello}")
// Checks:
/*
// Return original text if no open curly braces are found
if !string_count("{", text) {return (text);}
// More thorough, can be less performant, return original text if all curly braces are escaped
if (string_count("{", text) - string_count("{" + string(escape_open_brace_suffix), text) == 0) {return (text);}
*/
// Simple Formatting: format("Hello {}", "World");
if string_pos("{}", text)
{
for (var i = 0; i < argument_count - 1; ++i)
{
text = string_replace(text, "{}", argument[i + 1]);
}
}
// Positional Index Formatting: format("{1} {0}", "World", "Hello");
else if string_pos("{0}", text)
{
for (var i = 0; i < argument_count - 1; ++i)
{
text = string_replace(text, "{" + string(i) + "}", argument[i + 1]);
}
}
// Variable Formatting: var x = "World"; format("Hello {x}");
else if string_pos("{", text)
{
var variable;
var count = string_count("{", text);
for (var i = 0; i < count; ++i)
{
// Get variable name between curly braces
variable = string_copy(text, string_pos("{", text) + 1, string_pos("}", text) - string_pos("{", text) - 1);
// Ignore escaped curly brace "{|"
if (string_char_at(variable, 1) == escape_open_brace_suffix)
{
continue;
}
// If variable starts with "$", get global variable
if (string_char_at(variable, 1) == "$")
{
text = string_replace(text, "{" + string(variable) + "}", string(variable_global_get(string_copy(variable, 2, string_length(variable)))));
}
// Else get local variable from the calling instance
else
{
var t = self
text = string_replace(text, "{" + string(variable) + "}", t[$variable]);
}
}
}
text = string_replace_all(text, "{" + string(escape_open_brace_suffix), "{");
return (text);
}