5943539
|
  |
| Joined: 05 Jan 2010 |
| Total Posts: 810 |
|
|
| 12 Aug 2011 04:26 PM |
I couldn't get but one fail response to this in scripting helpers. So, in anger at that section of forums, I've decided to ask here.
Anyway I'm working on a section of script that sets a variable within loadstring to a matched string. It concatenates the match, but it treats the variable set as a string. i.e:
('x=6\n'):gsub('(%w+)=(.-)%c', function(f,s) local s=s pcall(loadstring('s='..s)) end)
Treats s as a string instead of a number. Any possible workarounds?
Math - The origin of all. |
|
|
| Report Abuse |
|
|
|
| 12 Aug 2011 04:27 PM |
| lol why did you call f as a parameter when you didnt need it |
|
|
| Report Abuse |
|
|
| |
|
5943539
|
  |
| Joined: 05 Jan 2010 |
| Total Posts: 810 |
|
|
| 12 Aug 2011 04:29 PM |
This is a snippet I wrote, from another script I wrote. It doesn't matter, though.
Math - The origin of all. |
|
|
| Report Abuse |
|
|
|
| 12 Aug 2011 04:32 PM |
('x=6\n'):gsub('(%w+)=(.-)%c', function(f,s) local s="s" pcall(loadstring('s='..s)) end)
|
|
|
| Report Abuse |
|
|
5943539
|
  |
| Joined: 05 Jan 2010 |
| Total Posts: 810 |
|
|
| 12 Aug 2011 04:35 PM |
What. You set s to something I can't use anymore.
Math - The origin of all. |
|
|
| Report Abuse |
|
|
Oysi
|
  |
| Joined: 06 Jul 2009 |
| Total Posts: 9058 |
|
| |
|
aboy5643a
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2785 |
|
|
| 12 Aug 2011 05:17 PM |
When dealing with stringed numbers do s = s + 0 to turn the string into a number. I hope I understood this right...
~Post here if you're Viet Namese, Canadian or Chinese. I'm from these 3 places. - Some confused kid from Language Center ~ |
|
|
| Report Abuse |
|
|
LPGhatguy
|
  |
 |
| Joined: 27 Jun 2008 |
| Total Posts: 4725 |
|
|
| 12 Aug 2011 05:19 PM |
@aboy5643a Or, use a better and faster version:
tonumber(s) |
|
|
| Report Abuse |
|
|
aboy5643a
|
  |
| Joined: 20 Nov 2010 |
| Total Posts: 2785 |
|
|
| 12 Aug 2011 05:20 PM |
Yes, that always works as well.. I always forget that method...
~Post here if you're Viet Namese, Canadian or Chinese. I'm from these 3 places. - Some confused kid from Language Center ~ |
|
|
| Report Abuse |
|
|
5943539
|
  |
| Joined: 05 Jan 2010 |
| Total Posts: 810 |
|
|
| 12 Aug 2011 05:28 PM |
Why doesn't loadstring get locals?
Math - The origin of all. |
|
|
| Report Abuse |
|
|