string = "write("hello")"
run(string)
Can anyone help me achieve something like this?
string = "write("hello")"
run(string)
str = "write('hello')"
loadstring(str)
"write("hello")"
But you can't use a pair of double quotes inside another pair of double quotes for the simple reason that it doesn't know where the string starts or ends. :(/>/>str = "write('hello')" loadstring(str)
PS: You can't call a variable 'string', as that's the name of a metatable allready.
PPS: You did:But you can't use a pair of double quotes inside another pair of double quotes for the simple reason that it doesn't know where the string starts or ends. :(/>/>"write("hello")"
Well you could do a combination ofThat's the easiest way I can think of
- make a temporary file
- store the code you want to run in it
- run the code with shell.run()
- delete the file
loadstring works - why not use that? Storing it to disk before running is just stupid.
I don't think that there is an equivalent to loadstring in C#. C# is a compiled language ,so the compiler has to know what code to use at compile-time, unlike interpreted languages such as lua.Wow I never knew of loadstring.
Thanks, this may be off topic but… what is the C# equivalent to loadstring?
It can be done, but not quite as easily as loadstring(). Basically, you need to use the CLR compiler on the user's machine to compile the code, and then load that assembly and execute a specific command in there through Reflection.Wow I never knew of loadstring.
Thanks, this may be off topic but… what is the C# equivalent to loadstring?
It can be done, but not quite as easily as loadstring(). Basically, you need to use the CLR compiler on the user's machine to compile the code, and then load that assembly and execute a specific command in there through Reflection.Wow I never knew of loadstring.
Thanks, this may be off topic but… what is the C# equivalent to loadstring?
Short answer: It's possible, but definitely not something to be undertaken by somebody who isn't intimitely familiar with C# and how the .NET Framework operates.
The best thing you can do is to get familiar with the command-line compiler for C# (the specific binary is csc), and how it operates. Then, get familiar with File I/O, and finally with Reflection – after you're comfortable with all of those, it shouldn't be very difficult to work out something that would work well.
Reflection is a way to search through metadata contained within .NET assemblies (DLLs & EXEs that use the .NET Framework) to locate and execute functions, instantiate classes, etc. It's a really powerful tool, and I'd say it's worth learning just for the sake of knowing it, but it could definitely help you accomplish your goal.
Edit:
This article on CodeProject may be able to give you a head start: http://www.codeproje...ET-Applications
rednet.open("back")
event, id, msg, distance = os.pullEvent("rednet_message")
loadstring(msg)
local foo = loadstring(blah)
foo()
The result of loadstring is a function - so do:local foo = loadstring(blah) foo()
function helloThere() -- Function name can pretty much be anything, just put () after it.
write("Hi There!") -- You can have a function do pretty much anything, as well...
write("Hi There!") -- Even multiple things. -- Just make sure to put an "end" after the function.
end
functionname() -- The name of the function goes here, with the ()'s after it.
print("Hi!")
write("> ")
local input = read()
if input == "Hi" then
functionName()
else
functionName2()
end
hello = "Hey There!"
write(hello)