Roblox Run Script From String in variable - lua

I'm trying to make a ss script that runs by turning the text inside the TextBox into a variable and running the variable as a script, how do I do this?
I tried to use loadstring but it didn't work, what do I do?
script.Parent.MouseButton1Down:Connect(function()
local script = script.Parent.Parent.TextBox.Text
loadstring(script)
end)

If no errors occur loadstring returns the loaded chunk as a function.
You failed to call that function.
assert(loadstring(script))()
Please read the Lua manual. https://www.lua.org/manual/5.1/manual.html#pdf-loadstring

Related

Script can't find tool in backpack

1. Summarize the problem
My script can't find the tool in the player backpack. The output of the print is always nil.
The toll is given by another script before the script that has to search it.
No error message appears.
2. Describe what you've tried
I've tried searching around but nothing fix my problem. I tried re-writing the code from 0 too.
3. Show some code
Simple script Code that clone the tool and place it in the backpack
script.Parent.Triggered:Connect(function(player)
local Frullato = game.ServerStorage.LemonadeStand.Tools.Frullato:Clone()
Frullato.Parent = player.Backpack
local Frappe = require(game.ServerScriptService.DummyMove)
end)
Simple script Code that can't find the tool. Print output is "nil"
script.Parent.Triggered:Connect(function(player)
local Smoothie = player.Backpack:GetChildren("Frullato")
print(Smoothie.name)
end)
Instead of :GetChildren() use :FindFirstChild(), and "Smoothie.name" should be replaced with "Smoothie.Name"

Is it possible to make it impossible for loadstring to be equal to print? lua

Is this possible? So lets say that we have this script: loadstring("print('Hello')")() this script is really easy to get the source from by just doing:
loadstring = print
loadstring("print('Hello')")()
Is it possible to disable this? Btw this is for my obfuscator
I am really sorry if this thread was confusing, Thanks
Maybe helpful: execute lua string as lua code.
So, the code must be:
trueloadstring = loadstring
loadstring = print
loadstring ("print('Hello')") -- prints "print('Hello')"
trueloadstring ("print('Hello')")() -- prints "Hello"

ROBLOX Studio: How do I run this Lua Bytecode VM?

For me, I want to learn how VM's work and if they can only be ran on Mac. I've found a bytecode vm (from lua) in roblox studio as one of the scripts. I'm very confused on how to use it, its nothing like i've used before. Here it is:
https://web.roblox.com/library/117513593/EpicLua-Lua-5-1-VM
Also if you could tell me more about VM's that would also help me during this process.
Looks like it's plug-and-play.
Require the module in a script/command line on Roblox. It will return a function which you can call with a string and desired environment (optional), which again returns a function you can run to run the string-code.
Example:
local LoadString = require(module)
local func = LoadString("print('Hello world!')")
func() -- prints "Hello world!"

Find name and location of Lua executeable

I need to find the name of the Lua executeable from within a Lua script as it sets up a task for later execution.
Using arg I can find out the name, however this becomes un reliable if options are used. For example, if no arguments are used running within a script print( arg[-1]) would print lua53. However if options are used they would be printed instead, such as -i, and to get the exe I would have change the line to print( arg[-2]).
What method will reliably get the name of the lua binary?
Try this
i=0
repeat i=i-1 until arg[i]==nil
i=i+1
print(i,arg[i])

Getting return status AND program output

I need to use Lua to run a binary program that may write something in its stdout and also returns a status code (also known as "exit status").
I searched the web and couldn't find something that does what I need. However I found out that in Lua:
os.execute() returns the status code
io.popen() returns a file handler that can be used to read process output
However I need both. Writing a wrapper function that runs both functions behind the scene is not an option because of process overhead and possibly changes in result on consecutive runs. I need to write a function like this:
function run(binpath)
...
return output,exitcode
end
Does anyone has an idea how this problem can be solved?
PS. the target system rung Linux.
With Lua 5.2 I can do the following and it works
-- This will open the file
local file = io.popen('dmesg')
-- This will read all of the output, as always
local output = file:read('*all')
-- This will get a table with some return stuff
-- rc[1] will be true, false or nil
-- rc[3] will be the signal
local rc = {file:close()}
I hope this helps!
I can't use Lua 5.2, I use this helper function.
function execute_command(command)
local tmpfile = '/tmp/lua_execute_tmp_file'
local exit = os.execute(command .. ' > ' .. tmpfile .. ' 2> ' .. tmpfile .. '.err')
local stdout_file = io.open(tmpfile)
local stdout = stdout_file:read("*all")
local stderr_file = io.open(tmpfile .. '.err')
local stderr = stderr_file:read("*all")
stdout_file:close()
stderr_file:close()
return exit, stdout, stderr
end
This is how I do it.
local process = io.popen('command; echo $?') -- echo return code of last run command
local lastline
for line in process:lines() do
lastline = line
end
print(lastline) -- the return code is the last line of output
If the last line has fixed length you can read it directly using file:seek("end", -offset), offset should be the length of the last line in bytes.
This functionality is provided in C by pclose.
Upon successful return, pclose() shall return the termination status
of the command language interpreter.
The interpreter returns the termination status of its child.
But Lua doesn't do this right (io.close always returns true). I haven't dug into these threads but some people are complaining about this brain damage.
http://lua-users.org/lists/lua-l/2004-05/msg00005.html
http://lua-users.org/lists/lua-l/2011-02/msg00387.html
If you're running this code on Win32 or in a POSIX environment, you could try this Lua extension: http://code.google.com/p/lua-ex-api/
Alternatively, you could write a small shell script (assuming bash or similar is available) that:
executes the correct executable, capturing the exit code into a shell variable,
prints a newline and terminal character/string onto standard out
prints the shell variables value (the exit code) onto standard out
Then, capture all the output of io.popen and parse backward.
Full disclosure: I'm not a Lua developer.
yes , your are right that os.execute() has returns and it's very simple if you understand how to run your command with and with out lua
you also may want to know how many variables it returns , and it might take a while , but i think you can try
local a, b, c, d, e=os.execute(-what ever your command is-)
for my example a is an first returned argument , b is the second returned argument , and etc.. i think i answered your question right, based off of what you are asking.

Resources