Sign in to follow this  

Getting Function Body From Script File

This topic is 2142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 [url="http://www.jython.org/"]http://www.jython.org/[/url], 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?

Share this post


Link to post
Share on other sites
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?

Cheers
~dd~

Share this post


Link to post
Share on other sites
That gave me an idea which I should consider.

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.

Share this post


Link to post
Share on other sites

This topic is 2142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this