Open file in current directory using lua script
-
Recently Browsing 0 members
No registered users viewing this page.
-
Similar Content
-
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; }
-
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now