Closed latenitefilms closed 4 years ago
Ok, first the objc module is... dangerous. Useful for examining things but please, please, please do not even slightly consider using it in production because:
a) it completely ignores all return type qualifiers about assign/copy/weak/etc. and treats every return value as strong
b) it has no concept whatsoever of structures and is useful only for methods which return actual objects or single value entities (numbers, boolean, etc.) or void
c) no concept of pointers (c-strings are an exception iff the return type can be known to be (unsigned) char *
or void *
)
d) will let you do dangerous and dumb things.
Whenever I use it, I plan on having to restart Hammerspoon or even reboot the computer soon.
Ok, with those qualifiers out of the way, it is an interesting way to poke at things and "see what they do"...
Glancing at what you've show above, it looks like you're pretty much on the right track, but remember, and method that takes a string, is expecting an NSString, so you'd have to do something like
o.class("PAEMD5Value")("alloc")("initFromString:", o.class("NSString")("stringWithUTF8String:", "my lua string"))
You can also assign things to variables, so...
n = o.class("NSString")("alloc")("initWithUTF8String:", "hello")
p = o.class("PAEMD5Value")("alloc")("initFromString:", n)
Don't forget to check out the metatables for the various types as well to learn about known methods, ivars, etc. There is limited ability to actually manipulate the ivars, but remember that in most non private cases, an ivar just backs a property, so for an ivar of _abc
, look for methods abc
and setAbc:
By default it also logs all of the interpretation of objective-c messages via LuaSkin's logDebug
, so you may want to temporarily change the log level (with hs.luaSkinLog.level
) or recompile with DEBUG_msgSend
commented out in objc.h
.
Legend, thanks heaps for the fast reply! HUGELY appreciated!
Yes, completely understood this is dangerous and can allow me to do really dumb things - duly noted!
I'm just going to use hs._asm.objc
to experiment within Hammerspoon - this definitely won't be used within CommandPost.
@asmagill - I'm trying to use
hs._asm.objc
to attempt to access some private functions in one of Final Cut Pro's Frameworks.I'm using this to load all the required Frameworks:
...which works as expected. But when I try and use
hs._asm.objc
to access these private functions, I get an error:Any ideas what I'm doing wrong?