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.