Jump to content
  • Advertisement
Sign in to follow this  
umbrae

Unity scripting language api - exposed class naming

This topic is 4811 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

I'm having a bit of difficulty deciding exactly how the C++ classes will be exposed in my scripting language. I'm currently designing my scripting api, so this thread is very interesting. I would quite enjoy hearing the actual details of why the current api's aren't so hot. Also if anyone has any ideas for how to nicely bind C++ and a scripting language it would be much appreciated. My current plan is to have an xml file that is hand edited to explain what you want to expose and how. This file is then read by a command line program that generates a cpp file with all the class function wrapper methods and a function with the same name as the file that, when run dynamically adds these definitions to the virtual machine runtime. I think this method isn't too bad because the xml file really contains exactly the information that you need. Comments and suggestions welcome. If everyone thinks that this way of doing things is okay, then on to my problem at the moment. Do you want to expose a C++ class into the scripting language with a different name? And if so, do you want to do the same with it's methods? Is this important functionality that I should include in my api?

Share this post


Link to post
Share on other sites
Advertisement
Might be okay, if you can get this command line utility integrated in your build process it probably wouldn't be too hard to keep the scripting language bindings up to date at all times.

However, you would still be required to update two places each time you change or add a function that is to be exposed to the scripting language. That's why I like the approaches of LuaBind and Boost.Python where the scripting language bindings are generated by template magic solely in C++ without a seperate command line utility.

-Markus-

Share this post


Link to post
Share on other sites
Yes that was the idea, a make file will be able to generate them easily.

mmm, template magic. Sounds interesting, but I distrust templates. I will have a look into them though.

Share this post


Link to post
Share on other sites
As a result of that thread, I'm playing with something new to see how it works out. I'm basically playing around with meta-classes. You declare a class definition in your application, attaching methods and properties to it. What you do then is ask the environment to make you an instance of that class; this is then usable in both the scripting environment and your native application. What's more, your 'native' classes can also be extended via the scripting langauge to add new methods, overrides or properties. The main drawback of this is that although you can access the meta-class instance in C++, it'd obviously be slower than using native code - the benefits are that there's not really a 'script' API any longer as the meta-class system and the scripting system share the same interface.

Again, not sure how this will pan out though - but it keeps me occupied at least.

Look at my journal for snippets...

Share this post


Link to post
Share on other sites
Quote:
Original post by umbrae
mmm, template magic. Sounds interesting, but I distrust templates. I will have a look into them though.


Oh, don't. Templates are wonderful things =)

I used a heavy template approach when writing gmBind, a C++ binding library for GameMonkey Script.

Share this post


Link to post
Share on other sites
Quote:
Original post by umbrae
I'm currently designing my scripting api, so this thread is very interesting. I would quite enjoy hearing the actual details of why the current api's aren't so hot.


1. Verbosity - if I have to type a lot to expose a function, it gets boring quickly. Similarly, if I have to check the number of parameters to each function, then the type of each of them, and write a 2-clause if statement for each, I'm gonna get bored and make mistakes.

2. Error-proneness - if the API is verbose or offers many different functions, it takes longer to look up what is needed for the binding and subsequently debug it.

3. Error-reporting facilities - generally you want the API to be able to detect when you misuse it (eg. you write a binding for a function that takes a double but you bind it as if it takes an integer), so ideally you want checked conversion operations and a well-defined place to report any errors.

4. Documentation quality - for example, the Lua documentation is quite comprehensive but poorly organised. A lot of the best binding functions are hidden in the extra libraries and not fully explained. Make sure your binding helper functions are clearly documented with examples.

Share this post


Link to post
Share on other sites
I think for the moment that I will stay with this xml method and see how far it goes. It might be an interesting idea if I also generate the class's .h file from the xml source as well. That way there would only be one place to make any changes.

I think it is a bit of a toss up between being able to expose already written C++ code (api's etc) or writing C++ for the scripting language directly. If you are trying to expose already written C++ code you don't want to make many changes, but C++ code for the language can be written it in a way that makes it easy to expose.

Since I'm starting with this language the latter is fine for me, but I also want other people to use it which means that it should be easy to bind. But if I want to expose any type of C++ class I need to support all the weird methods and heirarchy features of C++. My language doesn't have multiple inheritance is it okay to leave out support for this and other C++ language features? My plan was to just be able to expose one class, not a heirarchy. You will be able to setup a heirarchy in the scripting language, but it will behave like an object in my language, not a C++ object. ie every method is virtual etc.

Anyway, my original question is whether you want to expose C++ classes into the scripting language as a different name, and the same with methods. ie C++ class called "Scene" is actually exposed as "Scene3D" in the language. I think this would be good for libraries and cleaning up naming conventions.

[Edited by - umbrae on March 16, 2005 9:15:17 PM]

Share this post


Link to post
Share on other sites
Kylotan: Thanks heaps for your comments.

This is currently how I am envisioning binding classes to my language. This xml file is parsed and a .h file is generated. A C method with the same name as the file is also made and when called it registers the wrapper functions to the virtual machine.

<?xml version="1.0" standalone="no" ?>
<class name="bob" alias="bob_tyre">
<method name="print_a" type="void" />
<method name="number_id" type="int" />
<method name="distance" type="float">
<parameter name="x" type="int" />
<parameter name="y" type="int" />
</method>
</class>

<class name="dave">
<method name="print_a" type="void" />
</class>


So now in the scripting environment you can reference a class called "bob_tyre" and call methods from it. I still have to add a few more options to the xml file (to allow for a few of the cool features of my language) but it won't change much.

My code isn't commented, and it is all in the main function. But it does generate stuff.

Share this post


Link to post
Share on other sites
CPB is now working with C++, it should do what you need. Expect to see a new version that includes the new features in a few days.

http://www.thomasandamy.com/projects/CPB/

Share this post


Link to post
Share on other sites
Toes: I'm guessing that the technique that you use in CPB only works with x86? For me at least this isn't an option, my binding library needs to work on more platforms than just windows. Especially because I don't currently have a windows machine.

Interesting technique, but too low level for me.

edit: ooh, and I am not using lua, this is for my own scripting language.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Hive Entertainment
      I have already chosen my favorite from the concept artist which one do you like better 1 2 or 3?
       
      Also still looking for a writer and a 3d artist message if you are interested!

    • By Armaan Gupta
      Hey There,
      I am a developer and Im working on a blockchain based infinite runner type game. Right now, I am working on releasing the beta version with a couple other game developers, but would love to expand the team and have other talented and bright people contributing. The game portion of the project isnt very complicated, and wouldnt require anyone to pull thier hair out for it.
      If you are interested in joining a project, interested in the idea, or would like some more information, please don't hesitate to ask either by commenting, discord (username: Guppy#7625), or by email (armaangupta01@gmail.com).
      Thank you!
    • By Joydeep Mani
      I am trying to build a particle system for unity based on "Destiny particle architecture " released in Siggraph.
      I encounter a problem in trying to understand how they iterated this:

      Converted to spline function and the result is

      i wanted to know how did they converted the function in the editor to represent the graph ??
       
    • By Xerath Dragons
      This is my first experiment use for create my original character little cute dragon chibi use zbrush and blender and use unity3d assest free for enviroment scene you have feedback?
       


    • By Aryndon
      Project Redemption is an semi-fantasy RPG with a linear story and an elaborate combat system.
      We are building in Unity and are currently looking animators and artists.
      What we are looking for
      -Someone who is okay with split revenue/profits when finished
      -Collaborate with others in the team. Do you have an idea/thought on what should be included? Tell us!
      -Someone who wants to work with people that are passionate about this project
      If you are interested. Please message me and I will get back to you as soon as possible! Or add me on Discord AJ#6664
    • By Aggrojag
      Hello!
      I'm working on a game that is a narrative driven dark comedy with some small aspects of platforming and puzzle solving. The project is rather small as well. It touches on topics such as suicide, mental illness, family, corruption, free-will, and redemption.
      This project is exercise in polish, this means some experimentation will be needed along with some reworking of assets as they're provided.
      This will be a revshare model.
      First, I'm looking for a 2D sprite artist, not pixelated, that can compliment the style of the attached images, and be similar to the temporary character.
      We are looking to bring on a SFX designer at this time. Full list of required SFX will be available upon request, as well as a build with all elements related to sound implemented in some form (many SFXs pulled from the web for now). Will likely require some field recording, and some pretty strange SFX for when things get weird. I imagine a good portion of these will be quite fun to create.
      Lastly, I'm looking for a male voice actor, English should be your primary language. There will be at minimum two characters that will need to be brought to life through vocals. The first voice is similar to Marvin from Hitchhiker's Guide to the Galaxy. A reference for the second voice would be a mix of Ren (Ren & Stimpy), and Android 21 (DragonBallFighterZ). Due to formatting, I'm not including YouTube links in the post, sorry.
       
      WIP Scene with our custom shaders attached (platforms are lazily placed, as this was an asset test):

      A scene with dynamic lighting and temp character:

       
      Unshaded asset:

      If you made it to the bottom, thank you, and I look forward to hearing from you.
    • By SickTwistGames
      Ok, firstly, Hi.
       
      This is my first post on this forum. I am an Indie Dev making my first game so bear with me when I say dumb stuff, I'm on a huge learning curve.
       
      My first question is about inventory systems for unity. I am trying to make a survival type game with crafting. I have purchased Inventory manager pro by devdog from the unity asset store and it seems like a pretty powerful assett but for an intermediate coder its a little tough to use.  I'm beginning to wonder if it was the right purchase.
      So my question is.... does anyone have any experience of inventory plugins / systems for unity and can anyone reccomend a system to me?
      It needs to have the following: Loot system, crafting system, character sheet, blueprint system,  character stats system. Ideally with as little coding as possible.
       
      Thanks
    • By ethancodes
      I've got a bug with my brick breaker style game. The bricks move down one line at a time ever 1.5 seconds. What appears to be happening is occasionally the ball will be just about to hit the brick when the brick moves down a line, and now the ball is behind it. I'm not sure how to fix this. I have two ideas but I'm not sure of implementation. 1 solution would be to check where they were and where they are going to be before rendering the frame. Then if they crossed paths, then register the brick as hit. Solution 2 would be change how the bricks move. I could maybe slide them down line by line, instead of a jump down. I'm not sure of this will fix the issue or not. Any ideas?
    • By Pixeye
      I wrote an extension for unity inspector that allows to group/fold variables. 
      Available on github  , cheers!

       
    • By rakshit Rao
      I'M interested in programming tools (For animation, UI, etc). Can anyone suggest me the resources where I can start learning or which technologies I need achive it.
       
      Thanks,
      Rakshit
  • Forum Statistics

    • Total Topics
      631067
    • Total Posts
      2997736
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!