Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use variables inside a string in lua

Tags:

lua

In javascript we can do the following:

var someString = `some ${myVar} string`

I have the following lua code, myVar is a number that needs to be in the square brackets:

splash:evaljs('document.querySelectorAll("a[title*=further]")[myVar]')
like image 598
S. Schenk Avatar asked Jan 24 '26 01:01

S. Schenk


1 Answers

Function that fits your description is string.format:

splash:evaljs(string.format('document.querySelectorAll("a[title*=further]")[%s]', myVar))

It is not as verbose as ${}. It is more of a good old (and hated) sprintf.

like image 60
Green Avatar answered Jan 25 '26 17:01

Green



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!