Posted 25 September 2011 - 04:10 PM
I've worked around a bit with how gamemaker handles extensions and I've created a first extension:
Download gregex.gex from Host-A
Download gregex.gmz from Host-A
The GMZ can be opened with any unzip program. It can also be opened by directly typing the filepath + name into the "load gamemaker 8.1 file" bar when starting a new application.
This extension enables the use of regular expressions in gamemaker. (For those who don't know here is an extensive tutorial).
This build I've created over the night and today, so should be considered (literary) "nightly". There are some bugs in gm:html5 which prevent me from progressing further with the extension, as they depend on how gamemaker becomes.
Possible modifiers are: g - Global, for multiple matches in a string, i case insentive matching, m multiline matching. Multiple modifiers are possible by just "stringing" them together.
JSGregexMatch(heap, pattern, modifiers) - This function should be called first, it returns a "json" which has to be passed to the other functions. This function does the main calculation already, the rest of the functions are just to extract it.
JSGregexMatchNum(jsonResultString) - Returns the number of times the pattern was matched (if the modifier was set the g, "global"). If no match is found it returns 0
JSGregexMatchSubNum(jsonResultString) - Returns the number of subexpression matched
JSGregexMatchPos(jsonResultString, N) - Returns the position of the Nth match
JSGregexMatchResult(jsonResultString, N, Sub) - Returns the sub exppression "Sub" of the Nth match. Use "0" as Sub to retrieve the whole match.
JSGregexReplace(heap, pattern, modifiers, replacestring) - Searches for "pattern" in heap and replaces it (using "g" as modifier would mean to replace all occurences). Replacing can use "$1, $2, $N" to match the nth subexpression.
What have I learned
Testing is very annoying. Without the lack of a build in debugger you're forced to use bugzilla. Normally not a problem, however any mistake means the code fails to launch. And the error in bugzilla simply shows the obfuscated code so you have no idea where to look.
Gamemaker has a few bugs with extensions: sometimes extensions weren't "registered", sometimes it executed another function than I typed. Deleting functions from extensions cause access violations.
The extensions are copied, and the code is stored inside [project_folder]/extensions/[extension_name]/ editing this gives live changes to the code.
Gamemaker handles string literals "weird". Any "\" sign is changed to "\\" before converting to a string. This works good for "show_message". However for "draw_text", and when doing string manipulation this is unexpectedly weird.
GMFilesystem; When the sandbox is too limited (gex; GM:Studio)
Math, logic parser; Executing user inputted code in a complete safe manner (gex/script; GM:Studio)
Extended constants; (gex/script; all versions)