AHK Calling an lua-function from ahk

http://www.autohotkey.com/forum/topic44204.html

example_callLuaFromAhk.ahk   下面代码对原文错误进行了修改。

#include lua.ahk hDll := lua_loadDll("lua51.dll") l := lual_newstate() lual_openlibs(l) lual_dofile(l, "example_callLuaFromAhk.lua") sum := luaadd(10,15) msgbox, The sum is %sum% lua_close(l) lua_UnloadDll(hDll) return luaadd(x,y) { Global l ; the function name lua_getglobal(L, "add") ; the first argument lua_pushnumber(L, x) ; the second argument lua_pushnumber(L, y) ; call the function with 2 arguments, return 1 result lua_call(L, 2, 1) ; get the result sum := lua_tointeger(L, -1) lua_pop(L, 1) return % sum } 

example_callLuaFromAhk.lua 

function add ( x, y ) return x + y end 

你可能感兴趣的:(function,lua)