Re: embedding scripting into a program:a few questions

  • From: Andreas Stefik <stefika@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Sun, 7 Mar 2010 21:22:00 -0600

If I remember correctly, the reason the Blizzard folks chose LUA is because
you can directly call C++ functions from LUA and vice versa, similarly to
the way JNI works in Java, but supposedly much simpler. This basically
allowed blizard to create a LUA API which, behind the scenes, actually calls
C++ code formally.

As for inheritance, LUA is an object-oriented language, so it definitely
supports inheritance and classes. A quick google search confirms that that
is the case.

Another way that you can structure features in your system is to use what is
often called "Lookup." Basically, instead of inheritance, objects that
support a lookup interface can have features injected into them. For
example, the NetBeans platform architecture does this everywhere. If you
want a parser for a language, you just query lookup for a parser. If one
exists, an appropriate parser is returned. Or, if you are using an editor
and want to save a file, you query for a Saver (SaveCookie in NetBeans
speak), and if one exists, it is returned.

The nice part about this is that it allows third party developers to inject
their own features into your code in custom modules, basically allowing
people to come along and add "plugins" into your game. Our architecture on
Sodbeans also does this. It always takes new folks on our development team a
few days to wrap their head around it, but it makes everything very flexible
and customizable. If that's important to you, it's something to consider.

Stefik

On Sun, Mar 7, 2010 at 9:07 PM, Tyler Littlefield <tyler@xxxxxxxxxxxxx>wrote:

> Hello Laura,
> basically events are defined as a class, you can use += and -= to add
> and/or remove callbacks from the event, when the .invoke method is called,
> it will iterate through the list of callbacks and fire those.
> So, essentially the idea is to be able to do something like:
> player.OnConnect+=myfunc from the scripting language.
>
> In answer to your other question(s), I think. Basically i have a component
> class, and each class that inherits that can add it's own functionality. So
> the components are a plugin of sorts. For example, one component will hold
> stats like strength, dexterity, constitution, agility, inteligence, etc.
> That means that I can add this component to both players and mobs.
>
> Now, in the scripting language I use, I'd like to allow for builders/coders
> with the scripting ability to create a component from the scripting side of
> things. So maybe they want to add a component that will allow for a bot to
> talk to players. They could code the player-interaction component in using
> room-based events, and then every mob with player-interaction capabilities
> would just have to add that component to themselves and they'd be set. While
> this may be easier to just keep in c++, I'd really like to allow for people
> that don't know c++ so well to script this in with just as much ease.
>
> In answer to another question: I don't have a language picked out quite
> yet, that was sort of the idea of sending a message to the list. I'm looking
> for some ideas on what to use, and maybe some pointers on how to achieve
> what I want, as I haven't done this before.
>
>                Thanks,
> Tyler Littlefield
>        http://tds-solutions.net
>        Twitter: sorressean
>
> On Mar 7, 2010, at 7:53 PM, qubit wrote:
>
> > Hi Ty --
> > Ah, then you will have C++ versus a scripting language.
> > Could you elaborate on the nature of the scripting language? You say you
> > want to embed scripts in a program -- and that the script shouldn't
> control
> > the program, but rather interact with it, controling 1 component?
> >
> > You want the component to be able to call C++ methods, but you also want
> the
> > c++ part to be able to grab onto and control parts of the scripted
> > components, right?
> >
> > This is actually not hard, if you consider making it possible to send an
> > event or signal to the scripted component telling it to do something. How
> is
> > your base handling events?
> >
> > Also, it sounds as if you haven't chosen a scripting language yet.
>  Does
> > the language you are looking at provide a good translator and mechanism
> for
> > interfacing with the underlying code? (Actually, I'm sure it must, as
> that's
> > what a scripting language is for.)
> >
> > Since I have not been one to hang out in MUD's, I confess I'm not that
> > familiar with the end result of your base.
> >
> > You want to provide a base and scripting language for someone to use to
> > construct their own MUD?  Or are you implementing a MUD right now?
> >
> > In any case, let me know so I can be clear.  I'm up for a good puzzle
> right
> > now...
> > Happy hacking.
> > --le
> >
> >
> > ----- Original Message -----
> > From: "Tyler Littlefield" <tyler@xxxxxxxxxxxxx>
> > To: <programmingblind@xxxxxxxxxxxxx>
> > Sent: Sunday, March 07, 2010 8:29 PM
> > Subject: Re: embedding scripting into a program:a few questions
> >
> >
> > Hello Laura,
> > The idea is that the world class be able to be exposed to the language--I
> > don't need to add methods to the world class. What I do need to do, and
> what
> > seems to be causing the issue is the component setup; All components will
> be
> > loaded at startup and as they're added, but I need to be able to inherit
> the
> > c++ component class and add to it in order to create scripted components,
> > then I can just register them with the world class.
> > The issue is making the scripted components be usable. Obviously I can't
> > access a scripted component from c++, or I could through it's basic
> > functionality, but the idea is for the components to be able to be added
> to
> > any object whether scripted or not.
> >
> > Thanks,
> > Tyler Littlefield
> > http://tds-solutions.net
> > Twitter: sorressean
> >
> > On Mar 7, 2010, at 7:23 PM, qubit wrote:
> >
> >> Hi Ty --
> >> Did I read once that your base is implemented in C++?
> >> Let me clarify what you are saying you want to do:
> >> 1. class A in your scripting language needs to interface with class
> World
> >> in
> >> your base, and use its methods, and also to add methods of its own, and
> to
> >> do this dynamically. Right?
> >> 2. These new methods need to access class World in some way.  Do they
> need
> >> to go so far as to touch private or protected data?  Since you want
> >> dynamic
> >> insertion/removal of methods in class A, these methods will need to be
> >> able
> >> to work with World without being members of World.
> >> 3. As an aside, you could of course dynamically create a new inherited
> >> class
> >> C for each method m(), which is derived from World and therefore can use
> >> World's protected and public data.    m() can be a virtual or nonvirtual
> >> method.  But this all has to be done in the interface to your scripting
> >> language.  This is an interesting problem, as it almost requires that
> the
> >> scripting language have the same inheritance structure as C++ to make
> the
> >> implementation fall out cleanly.  But who ever heard of a clean
> >> implementation in the "real world"...*smile*
> >> Now, if your implementation goes so far as to create derived classes
> with
> >> their own virtual table for each function added to A, you will need some
> >> dynamic linking to pull it off.
> >> I'll have to think on this one for a while.
> >>
> >> Hey Ty, great job picking an interesting project.  That should go really
> >> well on a resumé.
> >> Happy hacking.
> >> --le
> >>
> >> ----- Original Message -----
> >> From: "Tyler Littlefield" <tyler@xxxxxxxxxxxxx>
> >> To: <programmingblind@xxxxxxxxxxxxx>
> >> Sent: Sunday, March 07, 2010 6:12 PM
> >> Subject: embedding scripting into a program:a few questions
> >>
> >>
> >> Hello all,
> >> As some of you may know, I'm working on a custom mud base that I will be
> >> releasing to the public and probably using for my own mud in the near
> >> future.
> >> I've got most of the stuff I want handled, except scripting; I was told
> to
> >> use Angelscript and was taking a look at it, but it seems to not be to
> >> well
> >> documented, so maybe someone has another idea.
> >>
> >> What I want, is to be able to make the world class (which stores a list
> of
> >> players, rooms, mobs, etc) accessible to the scripting language I use.
> >> Secondly, I want to expose events so that the language can attach it's
> own
> >> functions to them.
> >> Third and possibly more dificult, I want to expose my component system,
> >> which I will explain.
> >>
> >> Rather than using a is-a setup (through inheritance), I decided to go
> with
> >> a
> >> has-a setup. This provides some really cool ideas for design, such as
> >> being
> >> able to let clothing use containers if you decide that your shorts need
> >> pockets, without either moving container functionality up the
> inheritance,
> >> or using a multiple-inheritance setup, which can become messy. So, the
> >> components get loaded with the object from a list. I can easily use an
> >> AddComponent function to add the component to the list, but I'd like to
> >> allow builders and coders that I don't want using shell or that have an
> >> idea
> >> for a component to be able to build one in the language of choice, then
> >> register it with the dictionary that is used for holding components and
> >> allowing other objects to use this setup. So, in short I need a sort of
> >> transparent way to communicate back and forth, and not for the scripting
> >> language of choice to just control the driver, etc.
> >>
> >> Thanks,
> >> Tyler Littlefield
> >> http://tds-solutions.net
> >> Twitter: sorressean
> >>
> >> __________
> >> View the list's information and change your settings at
> >> //www.freelists.org/list/programmingblind
> >>
> >> __________
> >> View the list's information and change your settings at
> >> //www.freelists.org/list/programmingblind
> >
> > __________
> > View the list's information and change your settings at
> > //www.freelists.org/list/programmingblind
> >
> > __________
> > View the list's information and change your settings at
> > //www.freelists.org/list/programmingblind
>
> __________
> View the list's information and change your settings at
> //www.freelists.org/list/programmingblind
>
>

Other related posts: