I'm working on making a plugin that shows info on a script when it is selected, and know how to test for the selection and get the name, but how do I count how many lines it has?
You would have to get the source of the script(as Spongocardo stated) and reconstruct the entire text-I had already done something like this. This is heavily based off of BuildIn Libraries' Helper Library.
01 | function getSource(s) |
02 | local lines = { } ; |
03 | local str = "" ; |
04 | for i = 1 , string.len(s.Source) do |
05 | if (string.sub(s.Source, i, i) = = "\n" ) then |
06 | lines [ #lines+ 1 ] = str; |
07 | str = "" ; |
08 | else |
09 | str = str..string.sub(s.Source, i, i); |
10 | end |
11 | end |
12 |
13 | if (str ~ = "" ) then |
14 | lines [ #lines+ 1 ] = str; |
15 | end |
16 | return lines; |
17 | end |
Now you could do #lines to find how many lines it has.