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

Post by goreliu » 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: 4126
Joined: 11 Jan 2017, 17:59

Re: I wrote a LuaJIT FFI binding for AutoHotkey_H

Post by swagfag » 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

Post by Trigun » 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)
User avatar
hasantr
Posts: 770
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: Ben AutoHotkey_H bir LuaJIT FFI

Post by hasantr » 10 Oct 2020, 11:31

@goreliu Are we going to compile lua51.dll?
SOTE
Posts: 1211
Joined: 15 Jun 2015, 06:21

Re: I wrote a LuaJIT FFI binding for AutoHotkey_H

Post by SOTE » 16 Dec 2020, 05:42

This is very interesting. I wonder what various AHKers are doing with Lua, where they find it useful. Maybe Lua users might want to enlighten us more. Outside of the Windows OS, definitely many niches for Lua can be seen.
Post Reply

Return to “AutoHotkey_H”