|
| 12 Jan 2015 10:14 AM |
I've been playing around with getfenv() and I've discovered that you can run commands using it. EG: an alternative to loadstring.
It leaves an error after each use, it also can't work with loops (or anything that requires an "end") however, here is the code.
--------
getfenv().Code = getfenv(0)[print("Try this")..print("This works, then errors, then I can repeat it.")..Instance.new("Fire", workspace)]()
getfenv().Code()
----------
Now, this will print "Try this" and "This works, then errors, then I can repeat it." Then, it will instance a Fire into workspace. It will then leave an error: attempt to concatenate a nil value
Anyway, I hope you guys can find a way to use this, while keeping LoadString disabled. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 12 Jan 2015 10:17 AM |
That... That totally shouldn't work. What.
No I don't think you know what you did. Nice try, but take a look again and cry. |
|
|
| Report Abuse |
|
|
| |
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 12 Jan 2015 10:18 AM |
| (Psst, I'll just leave you to work out why it doesn't work because I'm not telling you) |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:21 AM |
print("Try this")..print("This works, then errors, then I can repeat it.")..Instance.new("Fire", workspace)
You're attempting to concatenate things that print and Instance.new returns, but in order to get what it returns, it actually fires them. Therefore you can fire functions and methods like this.
It cannot use end (and do, repeat, until, etc.) because it's they are keywords, not functions returning them. If you wrote up a function such as this
function ForIEquals(start, end, increase, func) for i = start, end, increase do func(i) end end
function X(var) print(var) end
You would be able to execute this:
getfenv().Code = getfenv(0)[ForIEquals(1,10,1, X)]()
getfenv().Code()
At least, I believe this is how it works. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 12 Jan 2015 10:27 AM |
| Ding ding ding you win 10^100^10 points |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:27 AM |
Adding on to my previous reply I think I should explain something else:
You will not be able to get rid of the error if you want to execute the scripts with more than 1 function execution in it, as it will be attempting to .. on nil (because they return nothing). However here's something small I wrote up:
function ExecuteScript(tab) for i = 1,#tab do getfenv(0)[tab[i]]()() --No need to use an unessecary variable end end
Although keep in mind you CAN NOT use keywords in this! You can only execute functions! Usage example:
ExecuteScript { [[print("Hello")]], [[print("How are you today?")]] }
If it does not work let me now. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:27 AM |
| A googolplex? Oh wait, a googolplex is 10^10^100. Not 10^100^10. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:32 AM |
@War, Thanks, I didn't try using functions with it.
|
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:36 AM |
| That doesn't work either, warspyking. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:39 AM |
| How about you both explain what you are doing and why you think it will work, so that I can try it myself? |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:41 AM |
@Jarod Right, so. This is basically attempting to run code using getfenv. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:41 AM |
| It works, however will always have an error at the end. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:43 AM |
I did it without an error. You jelly? Anyhow, that doesn't mean it works on strings. Your code doesn't work on strings, and Warspyking's code just doesn't work (especially on strings). |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:43 AM |
function ExecuteScript(tab) for i = 1,#tab do getfenv(0)[tab[i]]()() end end
ExecuteScript { [[print("Hello")]], [[print("How are you today?")]] }
I just tested this and it never worked... I do not understand why though. It uses the same method your script did.
However this works:
getfenv(0)[print("How are you today?")]()()
Which prints the error of
getfenv(0)[print("How are you today?")]()():1: attempt to call field '?' (a nil value)
I'm still testing this method because it really is weird and kinda hackish but extremely interesting. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:44 AM |
| Aha, thanks @Jarod for pointing out why it doesn't work. I'm putting in the literal strings of functions. Lemme try something different... |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:44 AM |
| I noticed. I'm still working on this stuff, I came across this though and thought I should post it. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:46 AM |
Aha, fixed it!
function ExecuteScript(tab) for i = 1,#tab do getfenv(0)[tab[i]]()() end end
ExecuteScript { print("Hello"), print("How are you today?") }
NO ERRORS!!!!!! |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:48 AM |
Yes, but that still doesn't use strings. On top of that, it probably only prints correctly because you run the print functions when you call ExecuteScript. That means that "getfenv(0)[tab[i]]()()" doesn't run the code segments you gave it. Even if it did, it still isn't a string. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:50 AM |
| The only negative about this is that you cannot do it dynamically from strings, therefore SBs or :script (:s) commands will not be possible. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 10:53 AM |
Yea, as @jarod has pointed out (he keeps getting to it before me -_-) my functions is literally completely usless.
function ExecuteScript() end
ExecuteScript { print("Hello"), print("How are you today?") }
Will even work.
The only reason this actually functions properly, is because to pass the arguments, the script needs whatever the heck print("Hello") returns, and which to do that, it fires the function. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 12 Jan 2015 04:14 PM |
ExecuteScript { print("Hello"), print("How are you today?") }
No no no you don't get it either. "Maybe you should read up a little before trying to teach something"
You're just making a table of the return literals, which are nil, which is an empty table. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 04:47 PM |
| @eLunate Please read this thread before posting, that is a way of executing code in a table. All my posts were basically a series explaining to epic how/why this actually worked. If you read my previous explanations you will see I know what I am doing. |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 12 Jan 2015 04:56 PM |
Try this
LolNilFunction {print("omg executed"); print("omg magic lol")}
It doesn't work how you think. |
|
|
| Report Abuse |
|
|
|
| 12 Jan 2015 05:06 PM |
eLunate You used it wrong. You have to define a function and pass those as arguments, then to pass it the script fires them to get what they return.
function Execute() end
Execute { print("hi"), Print("Waz up?") }
--hi --Waz up?
Or if you want to get clever about it:
(function() end) { print("hi"), Print("Waz up?") } |
|
|
| Report Abuse |
|
|