Jump to content




weird table syntax


  • You cannot reply to this topic
5 replies to this topic

#1 Creeper9207

  • Members
  • 211 posts

Posted 05 January 2017 - 09:14 PM

http://pastebin.com/Bcs8xVA2 <-- full code (sorry about readability)

to save you some time, i'll put here where i think the code is breaking:
Example 1
Example 2

Essentially, the idea is that the word 'function' is taken out of the string & put into a seperate drawing call to show up as blue, the problem is (line 232 in pastebin, example 2, line 16 in text post) is never called, meaning that (line 89-94 in pastebin, example 1, line 11-15 in text post) is not doing it's job, but IS called.

Edited by Bomb Bloke, 06 January 2017 - 12:18 AM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 06 January 2017 - 12:45 AM

View PostCreeper9207, on 05 January 2017 - 09:14 PM, said:

... meaning that (line 89-94 in pastebin, example 1, line 11-15 in text post) is not doing it's job, but IS called.

No, those lines aren't being called. If the term "function" existed anywhere within the strings in the "lines" table they would be, which would likewise lead to the final loop in the render() function doing something.

A couple of notes; in a conditional test, nil counts as false, and anything that is not nil/false counts as true. You can hence replace this sort of thing:

if beginp ~= nil then

... with this sort of thing:

if beginp then

... whereas "not beginp" would resolve as true if beginp were nil or false.

This loop here is redundant:

        for i = beginp, endp do
            lines[k]=string.gsub(lines[k],'function','        ')
        end

... and could be shortened to just:

        lines[k] = v:gsub('function','        ')

... though either way you'll only be able to highlight one instance of "function" per string; I assume that's not a problem for your purposes.

makeRenderObjects() is a redundant function - you only ever call it from one place in your code, inside the render() function, so why not just put its code in the render() function? Don't try to use function definitions in place of comments; making people scroll up and down to read linear code is annoying.

#3 Creeper9207

  • Members
  • 211 posts

Posted 06 January 2017 - 06:00 AM

in the actual file set, the code is divided into three files, to keep render() readable, makeRenderCode() is stored in a seperate file, here is what happens when "function" is typed: http://104.236.237.237/dem.mp4 (proof that gsub is being called)

The loop IS redundant, i just forgot to remove it because it originally :sub()ed every position in that range with " "

thanks for the notes, but still not sure why it's not working

Edited by Creeper9207, 06 January 2017 - 06:02 AM.


#4 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 06 January 2017 - 06:08 AM

Ah, so you're typing it in at runtime. That to me suggests that the entry exists in your renderObjects for just a fraction of a second before makeRenderObjects() gets called again, fails to find "function" a second time (because it removed it the first time...), and therefore doesn't stick it in the new renderObjects table.

Another thing I forgot to mention, did you intend to increment renderc at any point?

#5 Creeper9207

  • Members
  • 211 posts

Posted 06 January 2017 - 06:33 AM

i made a couple modifications, incremented renderc, created a tempvar, linus=lines, and replaced all instances of lines in makerendercode with linus, but it still cuts it out of lines for some reason (meaning the behaviour shown in the video still applies)

also, instead of formatting it for pastebin again, i just included all four files here:
http://104.236.237.237/tempdir/

Edited by Creeper9207, 06 January 2017 - 06:35 AM.


#6 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 07 January 2017 - 12:35 AM

When you attempt to assign a table to a variable, what you're actually doing is assigning a pointer that leads to that table. If you copy that pointer to a new variable, you then have two variables that point to the one table.

a = {}
b = a

a.someKey = "hello"
print(b.someKey)  --> "hello"

If you want to create a clone of a table then you need to make a new one and copy in the content from the old. Eg:

lines={"hello!","how you do","l3","l4","l5","l6","l7","l8"}

linus = {}

for i = 1, #lines do linus[i] = lines[i] end

Assigning functions and coroutines works the same way as with tables.

Again, you'd be better off merging your functions. Why even build a linus table to cache parsed content when you could just output it on the spot and then discard it?

Edited by Bomb Bloke, 07 January 2017 - 12:38 AM.






2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users