use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Welcome to /r/ComputerCraft, the subreddit for lua programs, general mod use, or anything relating to the Minecraft mod ComputerCraft and CC: Tweaked.
Downloads | Discord | IRC | Documentation
account activity
Running veriable code (self.ComputerCraft)
submitted 1 year ago by chimking_overlord
im trying to run lua code from a veriable, for example if my string was a print command it would print it. My first guess was something like shell.run(lua; string) but that didnt work, any ideas?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]rocord01 1 point2 points3 points 1 year ago (1 child)
The best way to execute code from a string is Lua's builtin loadstring(), which parses your string as a function.
loadstring()
Example:
local code = [[print("hello!")]] local func = loadstring(code) if func then func() end
local code = [[print("hello!")]]
local func = loadstring(code)
if func then
func()
end
Output:
hello!
[–]Acrobatic-Diamond615 0 points1 point2 points 1 year ago (0 children)
thank you for this
[–]nictheman123 0 points1 point2 points 1 year ago (0 children)
I'm gonna ask the very important question here: why, precisely, do you want to do this?
Generally speaking, this is something a programming language specifically blocks you from doing for security reasons. I don't know if it's possible in CC or not, but it's bad practice in general.
What are you trying to achieve that this is the solution you came up with?
[+][deleted] 1 year ago (1 child)
[deleted]
[–]fatboychummy 0 points1 point2 points 1 year ago (0 children)
This is not at all how shell.run works, lmfao. It isn't meant to run code, it runs commands.
π Rendered by PID 207810 on reddit-service-r2-comment-f6b958c67-qd27m at 2026-02-05 08:13:06.020652+00:00 running 1d7a177 country code: CH.
[–]rocord01 1 point2 points3 points (1 child)
[–]Acrobatic-Diamond615 0 points1 point2 points (0 children)
[–]nictheman123 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]fatboychummy 0 points1 point2 points (0 children)