I wrote a LuaJIT FFI binding for AutoHotkey_H

Post AHK_H specific scripts & libraries and discuss the usage and development of HotKeyIt's fork/branch
goreliu
Posts: 1
Joined: 10 Apr 2016, 22:22
GitHub: goreliu

I wrote a LuaJIT FFI binding for AutoHotkey_H

11 Jul 2020, 09:26

I wrote LuaJIT FFI binding for AutoHotkey_H v1. I hope someone will be interested in it.

Example

Code: Select all

local ahk = require 'ahk'

-- init()
ahk.init()

-- exec()
ahk.exec('MsgBox, exec test')

ahk.exec([[
    a := 333
    b := "getVar test"
]])

-- setVar()
ahk.setVar('b', 'getVar new test')

-- getVar()
print(ahk.getVar('a'))
ahk.exec('MsgBox, ' .. ahk.getVar('b'))

ahk.exec([[
Fun(Text) {
    MsgBox, % Text
    return Text
}

return

La:
    MsgBox, label test
    return
]])

-- func()
print(ahk.func('Fun', 'func test'))

-- label()
print(ahk.label('La'))

-- addScript()
ahk.addScript('MsgBox, addScript test', true)

-- execLine()
pLine = ahk.addScript('MsgBox, execLine test')
print(ahk.execLine(pLine, 3, true))

-- C()
local L = require 'utf8fix'.L
ahk.C().ahkExec(L'MsgBox, C test')

-- initWithText()
ahk.initWithText('#Persistent\nMsgbox, initWithText test %1%', nil, 'abc')

ahk.exec('Sleep, 2000')
Homepage

https://github.com/goreliu/luajit-ahk

Install

UNICODE version of AutoHotkey.dll should be put into the directory of lua51.dll first.

Install with luarocks:

Code: Select all

luarocks install luajit-ahk
Or download https://github.com/goreliu/luajit-ahk/archive/master.zip, use src/ahk.lua and src/utf8fix.lua.

API

Code: Select all

-- Load AutoHotkey.dll and call ahkTextDll with
--     #NoEnv
--     #NoTrayIcon
--     #Persistent
--     SetBatchLines, -1
-- return: true(success) false(error)
init()

-- script: A string with ahk script.
-- options: Additional parameter passed to AutoHotkey.dll.
-- parameters: Parameters passed to dll.
-- return: true(success) false(error)
initWithText(script, options, parameters)

-- scriptPath: A path to existing ahk file.
-- options: Additional parameter passed to AutoHotkey.dll.
-- parameters: Parameters passed to dll.
-- return: true(success) false(error)
initWithFile(scriptPath, options, parameters)

-- return: true(success) false(error)
exec(script)

-- return: true(success) false(error)
setVar(name, value)

-- getPointer: true(get pointer of variable) false(get the value, default)
-- return: string
getVar(name, getPointer)

-- Launch a Gosub routine in script.
-- return: true(label exists) false(otherwise)
label(name)

-- Like label(), but do not wait until execution finished. 
-- return: true(label exists) false(otherwise)
postLabel(name)

-- Launch a function in script.
-- return: string
func(name, ...)

-- Like func(), but run in background and return value will be ignored.
-- return: true(function exists) false(otherwise)
postFunc(name, ...)

-- return: true(therad is paused) false(otherwise)
pause()

-- return: true(therad is resumed) false(otherwise)
resume()

-- return: true(a thread is running) false(otherwise)
ready()

-- timeout: Time in milliseconds to wait until thread exits, default 0.
terminate(timeout)

-- timeout: Time in milliseconds to wait until thread exits, default 0.
reload(timeout)

-- script: Script that will be added to a running script.
-- execute: true(execute) false(do not execute, default)
-- return: A pointer to the first line of new created code.
addScript(script, execute)

-- pLine: A pointer to the line where execution will start or nil(default).
-- mode: 0(do not execute, default)
--       1(until return)
--       2(until block end)
--       3(only one line)
-- wait: true(wait) false(do not wait, default)
execLine(pLine, mode, wait)

-- path: Path to a file that will be added to a running script.
-- reload: true(reload) false(do not reload, default)
-- ignoreError: 0(signal an error if there was problem adding file, default)
--              1(ignore error)
--              2(remove script lines added by previous calls to addFile()
--                and start executing at the first line in the new script)
-- return: A pointer to the first line of new created code.
addFile(path, reload, ignoreError)

-- return: ffi.load('AutoHotkey')
C()
swagfag
Posts: 3972
Joined: 11 Jan 2017, 17:59

Re: I wrote a LuaJIT FFI binding for AutoHotkey_H

11 Jul 2020, 11:36

while im not particularly familiar with lua, more interop is always better, so well done and thanks
Trigun
Posts: 36
Joined: 29 Mar 2017, 01:33

Re: I wrote a LuaJIT FFI binding for AutoHotkey_H

29 Aug 2020, 05:48

i never used lua... so i don't understand the basic.... i can use lua and do the same stuff cheat engine scripts do?
i need a value from a getUser function and use that value on ahk, can i do that? (i need the EAX after the execution of the mono function)

Return to “AutoHotkey_H”

Who is online

Users browsing this forum: No registered users and 7 guests