I am trying to test out the Lua loadstring function.
This example is taken direction from the Lua documentation:
f = loadstring("i = i + 1")
However, when I try to run it at:
https://www.lua.org/cgi-bin/demo
I get the following error:
input:1: attempt to call a nil value (global 'loadstring')
loadstring
is not available in Lua past version 5.1. The demo you linked is running Lua 5.3. You can prove this by running the program print(_VERSION)
.
In Lua 5.2 an later your code should use load
, here is an example program you can run that loads a chunk from a string:
local f = load("return 2 + 2")
print(f())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With