Hello everyone! I have another fairly trivial question to ask.
As per suggestion last time, I decided to go with an existing scripting language instead of rolling my own. I've realized by now that that was ultimately a better decision.
Now, I am trying to build into my game editor a scripting section which will allow the user to modify the functions inside a script (some functions are generated by the GUI builder and other behavior can be programmed by the user). Creating the editor inside the builder and writing the code to save the text from the editor in the proper place in the file was a triviality. Now, I need to be able to read the code back and separate it by function.
My question is, is there some way I could use the jython interpreter, which I got from http://www.jython.org/, to handle this? I'm trying not to write a special parser just so I can separate the code properly. I know I can read in a class into an object (the level script contains a single class that describes the level) and operate on the separate functions, but is there any way to get the function code from that object in String format?
How about splitting them into multiple files? Put related functions (GUI generated etc) in a file, and show that to the user for editing. Is it really important to show each function separately? And if so, is it really important to store all functions in the same physical file?
I've made the script loader in such a way that I'm not really able to readily split the file into separate ones for each function. I've created an interface that defines the functions for a level script class object and the scripts implement said interface in their classes. Then my host code can parse the files, instantiate the script object that implements said interface, and it's functions can be used like that of a normal object. I'm not really sure how to replicate the "function pointer" functionality that I'd need if the functions were in separate files. XD What I meant probably makes no sense. It's basically: write level class implementing interface, and then in Java, instantiate the object and call it's function by the interface.