I am currently in the process of implementing a scripting engine into the core of my game engine. The language will not be incredibly advanced to start with; I just want to get it up and running, with a functional front- and back-end, and then I will add features.
One of the things I have been pondering about lately is the ability to call native engine functions from the script, functions that would be too slow for script execution. One of my current ideas is to map native functions in the engine to literal symbols, which would be easy to recognize and transform from the script manager/handler/whatever. On loading scripts, these symbols would then be substituted with function pointers, so that a lookup is not required on every native call.
My concern then comes to calling the native functions. They are not restricted to any number of specific parameters, so typedef'ing a common function type would not be practical. My idea was to write some assembly code to handle the loading of the different types of parameters, and then push those variables on to the stack. What I do not know, is how to do this efficiently. I am not that confident in the realm of assembly, but it would make it easier than doing it in C/C++ (if that is even possible). I have not decided on any final type of script stack, so anything is still possible. My first idea is to have two separate stacks: one for the script variables, and one for the values of the variable. The first stack of a common variable class, will hold different kinds of information on the values it points to in the second stack, which will just be an array of bytes, like offset, count and size. All the values of the script stack lay in a linear array, and I was wondering how different this is from the registers EBP/ESP. Would it be possible to just push the position of the first value on the value stack? This would remove any kind of formal-type recognition, and the need to write special code for different variable types.
Everyone is encouraged to toss any idea or suggestions you might have into the pool, everything will be appreciated. I have never done anything like this before, so all kinds of feedback is will surely help.
i've just taken the easy way out and made a switch sentence now my script lang is also only 10 instructions
if i understand you correctly this is exactly what you want
Just the article I was about to refer too I found it in Game Programming Gems
He he I have already read that document, and I am not comfortable with scripts being able to call all my exported function (my engine.dll has \~1400, core.dll \~900), especially not functions like 'appCoreExit()', 'appFatalExit()', 'GiveMyCharacterInfinteLifeAndAllWeapons()' and so on, you get my point.
But thanks for the reply, keep 'em coming!
i've just taken the easy way out and made a switch sentence now my script lang is also only 10 instructions [snapback]15031[/snapback]
10 instructions!?! My last VM had 140 instructions, and that was not even enough :blink:
Must be low in functionality...
Indeed it is
it's a stew of pic assembly and int 16.. with just the basic ops
but it works and it's fast as hell