v1.1.0
1.1.0
I was a little bored recently, so I threw together a generic metatable API. It was a quick little project, based on
earlier work for one of my many toy languages. This new API is kinda cool, but it in no way replaces proper metatables!
Basically it is intended for quick projects and temporarily exposing data to scripts. It was fun to write, and so even
if no one uses it, it has served its purpose :P
I really should have been working on more script tests, but this was more fun... Anyway, I have no doubt responsibility
will reassert itself soon...
Anyway, I also added two new convenience methods for table iteration, as well as some minor changes to the old one (you
can still use it, but it is now a thin wrapper over one of the new functions, so you shouldn't).
- Ran all code through
go fmt. I often forget to do this, but I recently switched to a new editor that formats files
automatically whenever they are saved. Anyway, everything is formatted now. (almost every file in minor ways) - Added
ProtectandRecover, simple error handlers for native code. They are to be used when calling native APIs
outside of code otherwise protected (such as by a call to PCall).Recoveris the old handler fromPCall, wrapped
so it can be used by itself.Protectsimply wrapsRecoverso it is easier to use. (api.go) - Added
ForEachRaw, basicallyForEachInTable, but the passed in function returns a boolean specifying if you want to
break out of the loop early. In other newsForEachInTableis now depreciated. (api.go) - Added
ForEach, a version ofForEachRawthat respects the__pairsmetamethod.ForEachRawuses the table iterator
directly and does much less stack manipulation, so it is probably a little faster. (api.go) - Added a new sub-package:
supermetaadds "generic" metatables for just about any Go type. For obvious reasons this
makes heavy use of reflection, so it is generally much faster to write your own metatables, that said this is really
nice for quickly exposing native data to scripts. From the user's perspective you just callsupermeta.New(l, &object)
andobjectis suddenly a script value on the top ofl's stack. Arrays, slices, maps, structs, etc should all work
just fine. Note that this is very new, and as of yet has received little real-world testing! (supermeta/supermeta.go,
supermeta/tables.go) - Added a new sub-package:
testhelpcontains a few test helper functions I find useful when writing tests that interact
with the VM. Better to have all this stuff in one place rather than copied and pasted all over... (testhelp/testhelp.go) - Modified the script tests in the base package to use the helper functions in
testhelprather than their own copies.
The API tests still have their own copies of some of the functions, as they need to be in the base package so they can
access internal APIs (stupid circular imports). (script_test.go) - Clarified what API functions may panic, I think I got them all... (api.go)