Skip to main content
gamedev.net
🔒 Locked

Compiled scripting language

Started by hlusnagen Nov 24, 2001 at 5:36 PM 0 replies 600+ views
Original Post
hlusnagen
hlusnagen
I have this idea to use a class a script: class CScript; Now, say that for each scripting language operation you have a function to go with it, and the function naming for it is always the same: // Use this naming conversion so you can have a function pointer typedef LPVOID (*SCRIPT_OP) (LPVOID pArgs,DWORD dwNumArgs); // Now for two test operations // Have a class for each operation class CScriptOP { SCRIPT_OP Function; // The main function that will be executed TCHAR* szName; // The name of the function, this will be the // operation name in the script itself. } There. Now a simple sat of basic operations that are the base of the language, just like assembler. Everything boils down to assembly language. // Add LPVOID Add(LPVOID pArgs, DWORD dwNumArgs) { DWORD dwSum; // simply add all the values in pArgs and return the final //sum for(DWORD dwCurrArg = 0L; dwCurrArg < dwNumArgs; dwCurrArg++) { dwSum+=DWORD(pArgs[dwCurrArg]); } return (LPVOID)dwSum; } Now there shuld be a table for all the functions posible in the scripting language, one in this case. CScriptOP ScriptOP[] = {{Add // Function pointers!, _T("add")} }; K, now that we have the table, we need the main script class class CScript { public: CScript(); ~CScript(); CScriptOP** ppOps; // ... } Here we have a basic class. ppOps is a pointer to pointer to the operations needed to execute in chronological order. In psudocode here is what the scripter needs to do to load and execute. First load. open file and read it into a buffer; do intermediate stuff to the script like find the starting point; see how much functions are called in the script and allocate enough memory for all of then to be stored in ppOps; while( all operations in file not traversed ) { get the bare name of the function, like "add"; while(ScriptOP has a function) { sheck if the function name in ScriptOP mackes the one in focus; if(Mach(the two names)) { //insert the the found function in the scripts function list ppOps[free function space++] = function on focus; brake; } } } // End By this time, CScript::ppOps is full of functions to call. Now all that is left it to call all the functions one by one, respectivly, with proper syntex. Anyway, I just had this idea and i wanted to let someone know bout'' it.
hlusnagen
hlusnagen
BTW: I alsow want to know what you think about this.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.