Jump to content




Load unfinished function


6 replies to this topic

#1 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 11 September 2016 - 12:05 PM

I'm working on a programm, who read a file line by line and run the content of the file with load(). But theres a problem: A function is in a file normaly in more than one line. For example:
function test()
print("test")
end
If load() only get "function test()" it gaves a error, that end exeptet. Why can I make this work?

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 September 2016 - 12:38 PM

Don't run individual lines of a file. This will screw up more than functions, local variables will not work. Since local variables are considered good practice, this will break the majority of programs.


What do you intend to accomplish by running individual lines of a file?

#3 Wilma456

  • Members
  • 187 posts
  • LocationGermany

Posted 11 September 2016 - 12:50 PM

I want to make a debugger with run a Programm line by line and show, waht the Program does and read/write Variables.

#4 TYKUHN2

  • Members
  • 210 posts
  • LocationSomewhere in this dimension... I think.

Posted 11 September 2016 - 02:57 PM

Warning: Psuedocode detected!

count = 1
everyOther = false
debugLine = "<some code here>"
load(readFunction)
function readFunction(file)
   if not everyOther then
	   line = readLine(count)
	   everyOther = true
	   return line
   else
       everyOther = false
       count = count + 1
	   return debugLine
   end
end

Edited by TYKUHN2, 11 September 2016 - 03:00 PM.


#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 11 September 2016 - 06:17 PM

View PostWilma456, on 11 September 2016 - 12:50 PM, said:

I want to make a debugger with run a Programm line by line and show, waht the Program does and read/write Variables.

This is, unfortunately, impractical within CC. It would work for only the simplest of programs - those without loops or local variables, or any number of things.

IIRC, the debug library is included with CCTweaks. That may be worth looking into if you want to make a proper debugging tool.

#6 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 11 September 2016 - 09:47 PM

One way to log all the functions called would be to set a custom env for the file which has an __index that wraps every requested function inside another one which then logs the stuff, or you return the original function and just log that the function has been accessed.

#7 Lupus590

  • Members
  • 2,029 posts
  • LocationUK

Posted 12 September 2016 - 01:10 PM

There are some debuggers on the forums already, here are a few from my bookmarks:
http://www.computerc...ps-like-a-boss/
http://www.computerc...-file-extracts/
http://www.computerc...-step-debugger/
http://www.computerc...k-trace-for-cc/

You may want to use them as reference.

Edited by Lupus590, 12 September 2016 - 01:10 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users