Jump to content

Recommended Posts

AutoIt3 Lua Wrapper

This is an AutoIt3 wrapper for the Lua scripting language. Consider it beta software, but since I will be using it in commercial product, expect it to evolve.

It has been developped with Lua 5.3.5. Updates will come for new Lua version.

Everything works just fine, except one (big) limitation: Anything that throws a Lua error (using C setjmp/longjmp functionality) will crash your AutoIt program. That means that it is impossible to use throw errors from an AutoIt function called by Lua (luaL_check*, lua_error...).

It is hosted in Github: https://github.com/matwachich/au3lua

Simple example

#include <lua.au3>
#include <lua_dlls.au3>

; Initialize library
_lua_Startup(_lua_ExtractDll())
OnAutoItExitRegister(_lua_Shutdown)

; create new execution state
$pState = _luaL_newState()
_luaopen_base($pState) ; needed for the lua's print function

$iRet = _luaL_doString($pState, 'print("Hello, world!")')
If $iRet <> $LUA_OK Then
	; read the error description on top of the stack
	ConsoleWrite("!> Error: " & _lua_toString($pState, -1) & @CRLF)
	Exit
EndIf

; close the state to free memory (you MUST call this function, this is not AutoIt's automatic memory management, it's a C library)
_lua_close($pState)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Belini
      I am testing version 2.0.0.0 which runs on windows xp but could not send any command to the player using StdinWrite () does this player support slave mode? Is it possible to send commands to MPV as they are sent to Mplayer?
    • By tbwalker
      I'm trying to build a script that will eventually create a log with time stamps of the active windows used on a workstation throughout the day, but I'm having a problem figuring out how to actually get this information.  For example, if someone has Microsoft Word open, I'd like to be able to pop-up/log "word.exe" along with the full path to that file if at all possible (sort of like seeing the application DETAILS name in Windows Task Manager and being able to right-click on the name and choose "Open FIle Location" to get the full path to the file).
      Is what I'm asking even possible within the realm of AutoIt?  I have the below script as a test that gets me the current active window handle and title in a message box every 6 seconds, but for the life of me, I don't know what code I need to use to get the actual .EXE name/path of the active window. 
      #include <MsgBoxConstants.au3> Local $i = 0 Do Global $handle = WinGetHandle("[ACTIVE]") Global $title = WinGetTitle("[ACTIVE]") MsgBox(0,"Active Handle & Title",$handle & " - " & $title, 3) $i = $i + 1 Sleep(3000) Until $i = 100 Any help or suggestions would be greatly appreciated.   I don't mind figuring out the code myself, if someone could just point me in the right direction.
       
      Thanks,
      TBWalker
    • By Zombie02
      Hello Guys i am new to Autoit. I am currently writing a GUI which is displaying a avi. My question now is how can i use a avi i added with Autoit3wrapper
      Thanks is advance
      Zombie
    • By gahhon
      I am not very sure if I am all right to post here tho. Due to other forums have no respond at all.
      So I have my custom make google chrome extension, and it will load unpack into Portable Google Chrome, but it keep pop up the alert box

      Is there any way to disable it? Because my Portable Google Chrome will load as Kiosk mode, so that user can't be uninstall/disable the extension.
      Many thanks in advance.
    • By Ascer
      Hello,
      I've read a article about lua functions here: https://debian-administration.org/article/264/Embedding_a_scripting_language_inside_your_C/C_code
      There are two ways of include lua scripts to your AutoIt code.
      1. Run lua functions by Autoit.
      2. Register Autoit function and run as lua.
      It's even possible to apply second way to AutoIt?
      As we can see on example there a few functions to make it possible.
      It's a lua file save as average.lua
      avg, sum = average(10, 20, 30, 40, 50) print("The average is ", avg) print("The sum is ", sum) This is a C functions to run lua. Can be convert to AutoIt ofc.
      There is a problem with func lua_register(L, "average", average)
      this function is not even detected in Lua51.dll
      We can use lua_pushcclosure instead.
      #include <stdio.h> #include "lua.h" #include "lualib.h" #include "lauxlib.h" /* the Lua interpreter */ lua_State* L; /* The function we'll call from the lua script */ static int average(lua_State *L) { /* get number of arguments */ int n = lua_gettop(L); double sum = 0; int i; /* loop through each argument */ for (i = 1; i <= n; i++) { if (!lua_isnumber(L, i)) { lua_pushstring(L, "Incorrect argument to 'average'"); lua_error(L); } /* total the arguments */ sum += lua_tonumber(L, i); } /* push the average */ lua_pushnumber(L, sum / n); /* push the sum */ lua_pushnumber(L, sum); /* return the number of results */ return 2; } int main ( int argc, char *argv[] ) { /* initialize Lua */ L = lua_open(); /* load Lua base libraries */ lua_baselibopen(L); /* register our function */ lua_register(L, "average", average); /* run the script */ lua_dofile(L, "average.lua"); /* cleanup Lua */ lua_close(L); return 0; }  
       
       
×
×
  • Create New...