Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2.0
- ::``class::{
- Send("{Backspace}")
- getInput(false, &className, &ph)
- writeConstructor(className, false)
- doubleEnter()
- writeFunctionsAndReturn(className)
- }
- ::``subclass::{
- Send("{Backspace}")
- getInput(true, &thisClass, &superClass)
- writeConstructor(thisClass, superClass)
- doubleEnter()
- writeFunctionsAndReturn(thisClass)
- }
- getInput(subClass, &firstInput, &secondInput) {
- local firstHook := createHook()
- firstHook.Start()
- firstHook.Wait()
- if not subClass {
- firstInput := firstHook.Input
- return firstHook.Input
- }
- local secondHook := createHook()
- secondHook.Start()
- secondHook.Wait()
- firstInput := firstHook.Input
- secondInput := secondHook.Input
- }
- createHook() {
- return InputHook(,"{Space}{Enter}")
- }
- doubleEnter() {
- Send("{Enter}{Enter}")
- }
- writeConstructor(thisClass, superClass) {
- writeDefinition(thisClass, superClass)
- Send("{Enter}")
- Send(thisClass . ".__index = " . thisClass)
- doubleEnter()
- Send("function " . thisClass . ".new()")
- Send("{Enter}")
- writeSelf(thisClass, superClass)
- Send("{Enter}{Tab}{Enter}")
- Send("{Tab}return self")
- Send("{Enter}")
- Send("end")
- }
- writeFunctionsAndReturn(className) {
- Send("function " . className . ":init()")
- Send("{Enter}{Tab}{Enter}")
- Send("end")
- doubleEnter()
- Send("function " . className . ":destroy()")
- Send("{Enter}{Tab}{Enter}")
- Send("end")
- doubleEnter()
- Send("return " . className)
- }
- writeDefinition(thisClass, superClass) {
- if not superClass {
- Send("local " . thisClass . " = {{}{}}")
- } else {
- Send("local " . thisClass . " = setmetatable({{}{}}, " . superClass . ")")
- }
- }
- writeSelf(thisClass, superClass) {
- Send("{Tab}")
- if not superClass {
- Send("local self = setmetatable({{}{}}, " . thisClass . ")")
- } else {
- Send("local self = setmetatable(" . superClass . ".new(), " . thisClass . ")")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment