スクリプトエンジンを作成したいと思い、奇妙な問題が見つかりました。 まず、私はそれが(多分)働く方法を説明します: スクリプトエンジン(DLL)は、使用されるアプリケーションに依存しません。メインプログラムのスクリプトエンジン - 不明な関数を呼び出す
// This will be called on beginning of host program, register set of functions, that
// script will provide to usere
SetFunc(void *func,byte code,char *descript);
func : pointer to existing function from host application (e.g. printf)
code : code for script compiler
descript : func description, if eventually needed
// function calling functions inc Script Engine (in compiled DLL, which can't be
// modified for host application, only input for SE is SetFunc
CallFunc(void *instr);
instr : pointer to memory block, in which is stored
(instr_code - byte)(void* - pointer to func)(params_len - unsigned int)(params - data block)
/\--- this will be filled after loading script to SE, according to table of registred functions (via Setfunc).
Callfunc(void *func,void *params,unsigned int param_length);
func : pointer to function
params : parameters for function in memory block (extracted from instr)
param_length : what to say :o)
例:
#include "ScriptEngine.h" // this will create connection to SE DLL
float add(double num1,double num2)
{
return (num1+num2);
}
int main()
{
SetFunc(add,1,"f:d,d/2"); // register one function to SE
LoadScript("simple.sc","simple"); // load script to memory
ExecuteScript("simple"); // execute script (only add two nums)
}
、スクリプト:
main()
{
add(3.45,8.87);
}
// after some compilation to binary format :
...
(1)(NULL)(16)(3.45)(8.87) (instruction for "system call" (registred via SetFunc)
...
// after LoadScript
(1)(0x00402cc)(16)(3.45)(8.87)
そしてExecuteScriptのSEは、2つの機能を(このsomelike、それは少し異なる場合があります)をエクスポートします内部DLL関数CallFuncを呼び出し、instrからの入力パラメータを設定します。
この環境でポインタから関数を呼び出してパラメータを設定する方法はありますか?私はこの方法でこれを作成することができますか、または誰かがこれを行う方法、別のアイデアを持っていますか?すべての答えのための
ありがとう:O)
本当に答えはありますが、なぜluaなどを使用しないのですか?これは広く使用されており、独自のプロジェクトが拡張性があり(メタテーブルを使用した構文でさえ)、実装が簡単なものよりも安定しています。 tolua ++のようなC++用のバインディングライブラリがあります。これは、C++関数を自動的にluaでアクセス可能に変換します)。 30分以内に設定することもできます。 – Cray
私はそれについて考えてきましたが、私には好きではないものがあります。しかし、ありがとう、私はこれを私の心に残しておきます:o) –