獲取表腳本的全部內容(包括註釋)?我正在嘗試提出一個系統來組織附加到我的數據表的所有JSL腳本。我想在每個腳本頂部的註釋中插入標題。它看起來像這樣:
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * **
* Script Name: my script name
* Script Category: <<CATEGORY>>
* Author: author name
* Rev Date: date
* Purpose: purpose
* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */</CATEGORY>
在此標頭中,我將保留一些有關每個腳本的元數據。例如,括在尖括號中的“腳本類別”字段。我希望能夠遍歷腳本並根據此元數據對其進行操作。
我知道我可以像這樣獲得連接到我的數據表的所有腳本的列表:
dt = Current Data Table();
scriptList = dt << Get Table Script Names;
然後,我可以獲取如下腳本的內容:
scriptText = Char(dt << Get Table Property(scriptList[1]));
但是,scriptText不包含任何註釋。標頭部分丟失,因此我無法訪問這些註釋中包含的元數據。
有沒有辦法讓滿的表腳本的文本,包括註釋?
腳本編寫回复:獲取表腳本的全部內容(包括註釋)嗎?我知道解決此問題的唯一方法是將每個註釋放入虛擬文字字符串中
dt=current data table();
eval(parse("\[dt << new script("mysct",
comment="/**************************************/";
names default to here(1);
dt=current data table();
comment="// Here come more comments";
;]\")); 回复:獲取表腳本的全部內容(包括註釋)嗎?謝謝。那就是我所擔心的-除了在事物的評論方面使用某種醜陋的kludge之外,無法以編程方式訪問這些評論。
我確實找到了一種看起來更好的方法來完成此任務。我將標題註釋塊放在JSL Quote()的內部,這會欺騙JSL解釋器保留我的註釋塊而不是刪除它。現在,我可以閱讀類別字段並相應地使用它。
這是我的示例腳本:
JSL Quote(
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * **
* Script Name: my script name
* Script Category: <<MY category="">>
* Author: author name
* Rev Date: date
* Purpose: purpose
* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */
);
//this comment will be deleted
dt = Current Data Table();
scriptText = Char(dt << Get Table Property("my script name"));
scriptCategory = Char(Regex(scriptText,"\<\<([A-Za-z0-9 \/]*)\>\>", "\1"));
Write("\!n" || scriptText || "\!n");
Write("\!n" || scriptCategory || "\!n");</MY>並輸出到日誌:
JSL Quote(
/* ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * **
* Script Name: my script name
* Script Category: <<MY category="">>
* Author: author name
* Rev Date: date
* Purpose: purpose
* * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * ** * */
); dt = Current Data Table(); scriptText = Char(dt << Get Table Property("my script name")); scriptCategory = Char(Regex(scriptText, "\<\<([A-Za-z0-9 \/]*)\>\>", "\1")); Write("
" || scriptText || "
"); Write("
" || scriptCategory || "
")
my category</MY>