Jump to content

  • Log In with Google      Sign In   
  • Create Account


Getting Function Body From Script File


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 boogyman19946   Members   -  Reputation: 1029

Like
0Likes
Like

Posted 06 March 2012 - 12:56 PM

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?
"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^

Sponsor:

#2 darkdesigns   Members   -  Reputation: 100

Like
0Likes
Like

Posted 06 March 2012 - 01:28 PM

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~

#3 boogyman19946   Members   -  Reputation: 1029

Like
0Likes
Like

Posted 06 March 2012 - 09:42 PM

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.
"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS