katsaii / catspeak-lang

A cross-platform modding language for GameMaker games.
https://www.katsaii.com/catspeak-lang/
MIT License
94 stars 6 forks source link

Dev 3.1.2 - Added `catspeak_get_self` and `catspeak_get_index` #140

Closed tabularelf closed 2 months ago

tabularelf commented 2 months ago

This PR introduces catspeak_get_self and catspeak_get_index, which play as counterparts to method_get_self and method_get_index. The reason for this is that method_get_index will return __catspeak_function__ or __catspeak_method__ from Catspeak programs. And even then, not as a method but as a GML function index. That's likely to cause all sorts of issues. method_get_self also has the unfortunate issue where it could return the Catspeak program struct itself. Which may also be unintended depending on who you ask.

catspeak_get_index resolves this by always returning a method. Never a function ID. This means that any Catspeak functions or Catspeak methods, will always return their callee program "as is". And any GML function will be returned as a method with a bound to undefined.

catspeak_get_self resolves this by returning self from only GML functions and Catspeak methods. Anything marked as a Catspeak function (via is_catspeak) will retrieve self_ via accessor (if it exists), or returns undefined.

katsaii commented 2 months ago

Can you add a couple of tests to validate the behaviour works, please?

tabularelf commented 2 months ago

Included a couple unit tests as per request!