• entries
437
1000
• views
337028

# GM Stuffz

282 views

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 dataeventsystem.broadcast("myevent", { name = "test", size = 50 });	// send "mysevent" to all objects with a table for dataeventsystem.send(obj, "myevent");	// send "myevent" to obj with no dataeventsystem.send(obj, "myevent", { name = "test", size = 50 });	// send "myevent" to obj with dataeventsystem.send( { obj, obj2, obj3 }, "myevent");	// send "myevent" to obj, obj2, obj3 with no dataeventsystem.send( { obj, obj2, obj3 }, "myevent", { name = "test", size = 50 });	// send "myevent" to obj, obj2, obj3 with dataeventsystem.remove(ent, free_standing_handler);  // remove this object event handler functioneventsystem.remove(ent, "myevent");  // remove all handlers for this event on the objecteventsystem.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}...signal("somesignal");

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.

There are no comments to display.

## Create an account

Register a new account