Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Lua loadstring() not work on the demo site?

Tags:

lua

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')
like image 464
Dr.YSG Avatar asked Sep 19 '25 18:09

Dr.YSG


1 Answers

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())
like image 76
azdle Avatar answered Sep 23 '25 12:09

azdle



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!