Ok, now I at least understand what you want to do. But still I don't know why you have a problem.

When you call a function, it does not matter how you got its pointer, as long as it's the right one. The function itself does not know that you called engine_getscript before. It just executes and returns.

Maybe something else in your project causes a problem? For testing, write a simple script that just gets and calls your function pointer. Check if it returns correctly. Also check if you've defined the prototype correctly and if you're really calling the right function pointer.