Jump to content
  • Advertisement
  • entries
  • comments
  • views

GM Stuffz

Sign in to follow this  


I've been thinking about what else I can do to extend GameMonkey Script - bearing in mind that this isn't actually my language, nor am I a maintainer of it - I'm simply one of the active community members with an interest in improving the language. The recent foreach extensions I added are nice and I think add something to the language, as do the switch and custom type iteration features that I put in as well.

I'm getting to the point where I want to do something more. One of the features I'm thinking of pulling over from other languages is that of closures. GameMonkey has no concept of lexical scoping at the moment, so I'd have to figure out to how to integrate that into the language. I think I could borrow the upvalue concept from Lua here as internally, both languages work in a similar way.

I'm also considering the merits of adding object-based events to the system. These would be similar (in a way) to the blocks and signals we have already but would work more on an object-based level.

The 'event' type would be a simple pair of "eventVar" and "eventData", so that you can send data along with an event, unlike a signal.

ent = CreateSomeObject();

free_standing_handler = function(obj, evt)
print(evt.event, "fired on ", obj);
print("data passed:", evt.data);

eventsystem.register(ent, "myevent", free_standing_handler); // add_handler(object, eventvar, handlerfunc);

eventsystem.broadcast("myevent"); // send "myevent" to all objects with no data
eventsystem.broadcast("myevent", { name = "test", size = 50 }); // send "mysevent" to all objects with a table for data

eventsystem.send(obj, "myevent"); // send "myevent" to obj with no data
eventsystem.send(obj, "myevent", { name = "test", size = 50 }); // send "myevent" to obj with data

eventsystem.send( { obj, obj2, obj3 }, "myevent"); // send "myevent" to obj, obj2, obj3 with no data
eventsystem.send( { obj, obj2, obj3 }, "myevent", { name = "test", size = 50 }); // send "myevent" to obj, obj2, obj3 with data

eventsystem.remove(ent, free_standing_handler); // remove this object event handler function
eventsystem.remove(ent, "myevent"); // remove all handlers for this event on the object
eventsystem.remove(ent); // remove this object entirely

When the event is sent, a new thread is created passing obj as 'this' and calls the specified handler.

This should be easily achieveable by creating a binding and wouldn't need any internal modifications - except maybe the garbage collector, which would have to notify the event system of an object being destroyed to ensure that all dangling pointers to native objects are removed and avoid a crash when an event fires on a deleted object. This means that the event system would be passive and not own any references.

Another addition I'd like to make is to change the signal system to allow people to pass data with a signal and be picked up by the block function. This would involve a couple of minor tweaks to the system and the assignment of several operators to make sure the current use still works:

res = block("somesignal", "anothersignal");

if (res == "somesignal")
// do something



This could be changed to create the signal as an object with two members, sig and data. sig is the actual signal variable and data would be optional data. It would let you do things like:

res = block("somesignal", "anothersignal");
if (res == "somesignal") // or res.sig == "somesignal" would work, the equals operator would forward to this var
print(res.data, " data sent with signal");


signal("somesignal", "hello"); // string hello sent as data, could be anything

This would let you do simple message passing between threads (or multiple threads).

Part of me wonders about starting out and doing my own language, but GM is so well-designed and easy to extend there doesn't feel like there's much need to.
Sign in to follow this  


Recommended Comments

There are no comments to display.

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
  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!