포럼: 도움 (Thread #8403)

スクリプト内の関数をアプリケーション側から呼ぶ (2005-08-14 22:11 by Anonymous #15806)

スクリプト内の関数をアプリケーション側から呼ぶ事はできるのでしょうか?
以下のような感じで使いたいのです。

//スクリプト側
function testFunc (a, b) {
println(a + b);
}

obj = new TestObj();
obj.call(testFunc);

//アプリケーション側(TestObjクラス)
function TTestObj.call(Param: TJValueList): TJValue;
begin
//ここで引数を設定して testFunc を呼ぶ
end;

Reply to #15806×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: スクリプト内の関数をアプリケーション側から呼ぶ (2005-08-16 19:57 by shobohn #15831)

こんな感じでしょうか

function TTestObj.call(Param: TJValueList): TJValue;
var
v: TJValue;
prm: TJValueList;
begin
EmptyValue(Result);
if IsParam1(Param) then
begin
v := Param[0];
if IsFunction(@v) and Assined(FEngine) then
begin
prm := TJValueList.Create;
try
prm.Add('関数に渡す引数1');
prm.Add('関数に渡す引数2');
Result := TJEngine(FEngine).CallExpr(v.vFunction,prm,Self);
finally
prm.Free;
end;
end;
end;
end;
Reply to #15806

Reply to #15831×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: スクリプト内の関数をアプリケーション側から呼ぶ (2005-08-16 20:25 by shobohn #15832)

補足です。

ユニットのimplementation以下に

uses ecma_engine;

を追加してください。
Reply to #15831

Reply to #15832×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: スクリプト内の関数をアプリケーション側から呼ぶ (2005-08-16 20:47 by shobohn #15833)

×Assined
○Assigned
です。
Reply to #15832

Reply to #15833×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

ありがとうございます。 (2005-08-17 05:48 by Anonymous #15842)

質問させていただいた物です。

御陰様でうまいこと実装できました。

アプリケーション側で持っているある程度の多さのデータから条件に基づくデータのみ抜き出す・・
ということがやりたかったのですがこれで複雑な条件でも問題なくなりそうです。
Reply to #15806

Reply to #15842×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login