DPLX
|
  |
| Joined: 10 Dec 2014 |
| Total Posts: 768 |
|
|
| 26 Jan 2015 08:31 PM |
Is there any easy way to do this?
Ex:
"{1,2,3,4}" -> table = {1,2,3,4}
:) |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 08:32 PM |
If I remembered all the fancy script commands I could probably help...
(But I don't, sorry) |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 08:33 PM |
----- str = "{1,2,3,4}" tble = loadstring(str)() ----- |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 08:33 PM |
| Just use JSON encoded tables, it is more correct. |
|
|
| Report Abuse |
|
|
| |
|
DPLX
|
  |
| Joined: 10 Dec 2014 |
| Total Posts: 768 |
|
|
| 26 Jan 2015 08:34 PM |
Is there a way to do it without loadstring?
Doesn't LoadStringEnabled allow hackers and all that or something
I dont remember -_-
:) |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 08:35 PM |
Not really. Not if you use FE.
But just use JSON tables. |
|
|
| Report Abuse |
|
|
DPLX
|
  |
| Joined: 10 Dec 2014 |
| Total Posts: 768 |
|
|
| 26 Jan 2015 08:37 PM |
So something like
JSONDecode(JSONEncode('{1,2,3,4}'))
?
I know its not correct syntax but you get the idea
I don't know a lot about JSON :(
:) |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 08:39 PM |
| It's pretty much that, but JSONEncode takes a table, and JSONDecode takes a string. JSONs actually have square brackets, not the curly ones. |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 08:40 PM |
Correction to my post: ----- str = "{1,2,3,4}" tble = loadstring("return "..str)() ----- Yes, loadstring may increase vulnerability to exploits.
Use for loops and string.gmatch to iterate through the string and look for strings matching ".+," and ",.+", then use string.sub to remove the commas. |
|
|
| Report Abuse |
|
|
DPLX
|
  |
| Joined: 10 Dec 2014 |
| Total Posts: 768 |
|
|
| 26 Jan 2015 08:41 PM |
Alright, I think I got it now.
Thanks!
:) |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 26 Jan 2015 08:42 PM |
| Don't bother trying to your own tokenization function. JSON will support multidimensional tables, different datatypes, libraries, etc. It's so much easier to use too. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 26 Jan 2015 08:47 PM |
local tab = "{1,2,3,4}"
function makeTable(str) local tab = {} for i in str:gmatch("%d") do table.insert(tab,i) end return tab end
local tabl = makeTable(tab)
print(unpack(tab1)); |
|
|
| Report Abuse |
|
|
|
| 26 Jan 2015 08:50 PM |
@goul
"for i in str:gmatch("%d") do" Only works for numbers. Use .+ instead.
But yes, just use JSON. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
| |
|