lualike - execute lualike scripts dynamically

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
Brazolek123
Posts: 187
Joined: 06 Jun 2016, 16:02

lualike - execute lualike scripts dynamically

18 Sep 2017, 14:16

Tbh posting it because that someone might want to improve it. Since couldn't find any working lua-ahk libraries neither any script parsers/interpreters decided to create my own.

Credits: ExprEval() by Uberi, Eval() by Pulover [Rodolfo U. Batista]

download: https://github.com/Brazyliszek/ahks-LUAlike

Main function is: execute(script) where script is variable in which code to execute is stored.
Code is executed line by line.
It got acces to all main scripts internal functions and variables (might create white and black list one day)
Also created own syntax which is mix of C and LUA I guess, will be described later. It contains simple watchdog that checks syntax before execution and show msgboxex with problem description and at which line problem occured.
Expression 'goto' and 'label' allow you to create loops.
Function returns 1 if execution was successful, otherwise 0.

Limitations:
short variable names like "i" or "a" might result in unexptected behaviour
multi-if statements are not allowed:

Code: Select all

if (a>b)
	then
	if (b>c)		; <--   wrong!
		then...
	endif
endif
Syntax description:
start - expression that should be placed at beginning of each script
end - as above, but ending the script
function_name(arg1, arg2); - functions must be declared in main script, not recognition will return error, also funcs must be ended with ";"
variable := 4*233*int_variable*function(arg1); - variable assignments must contain ":=" and must be ended with ";"
// some comment - comments starts with "//", line is not ignored but its iterating and jumps to the next one
if ((a = b*c) and (b >=c)) - just like in ahk, except for that brackets are obligatory
then - after if expression 'then' is necessary
else - after 'then' you can place 'else'
endif - each if statement must be closed with 'endif'
goto label_name - it will jump to the line with 'label_name'
label_name: - single worded line ended with ":" is interpreted as label

Lualike script example:

Code: Select all

start
console("Start");
// comment 
if (A_ScreenWidth > 1000)
	then
		console("Screen width is wider than 1k px.");
	else
		console("Screen width is not wider than 1k px.");
endif
varCount := 0;
loop_label001:
if (varCount <= 5)
	then
		console("Loop count: "  . varCount . ".");
		varCount := varCount + 1;
		goto loop_label001;
endif
console("End");
end

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: NPerovic and 60 guests