Jump to content




[API] SmartWrite: New write API for easier writing.


16 replies to this topic

#1 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 18 September 2012 - 04:39 PM

I have written my first API to be used to help shorten some of the tedious calculations most of us go through to have the words we type show up in a specific area of the screen. Included is a center printing function, right justifying, fraction justifying, and vertical printing. Also included, but not too noteworthy is a terminal clearing function, that clears, the whole screen, and returns to the specified x and y positions. This will save most people ONE WHOLE LINE OF CODE! The same goes for the line clearing function, but it will just clear the specified line, and return to the previous position, saving up to three whole lines. This is my first API, so I would greatly appreciate any suggestions or constructive criticism as I learn to make this better.
Code:
http://pastebin.com/dXamY7Jc

Methods:
Spoiler

Edited by Cranium, 09 November 2012 - 01:01 PM.


#2 GopherAtl

  • Members
  • 888 posts

Posted 18 September 2012 - 04:56 PM

Simple but useful, no particular criticisms except to say it would be easier to follow if you fix the indentation throughout and threw some blank lines to separate functions, it sortof runs together right now.

As for suggestions, you could add support for an optional monitor parameter to each function. Just replace term with that parameter and, at the start, if it's nil set it to term. When the new version comes out, you might be able to support printers the same way (not certain, not in beta so dunno what the actual printer peripheral interface is like).

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 18 September 2012 - 05:01 PM

I didn't even think about monitors, but I can see where it would be a little more useful there. So just do local term = term or mon? Not sure how i would implement monitors in. As I said, it's my first API.

#4 GopherAtl

  • Members
  • 888 posts

Posted 18 September 2012 - 05:08 PM

well, you could use a local term variable, I was thinking of using the parameter

ex using clear:

function clear(x,y,screen) --will clear the screen, and return to the specified x,y position
  --default screen to term if it is nil
  if not screen then screen=term end
  --use screen from here on
  screen.clear()
  screen.setCursorPos(x,y)
end


#5 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 18 September 2012 - 06:21 PM

So for example:
function clear(x,y,peripheral)
if not peripheral then mon = term end
mon.clear()
mon.setCursorPos(x,y)
end
So just to make sure, the user would have to use their own peripheral.wrap() function to determine the peripheral parameter, right?

#6 GopherAtl

  • Members
  • 888 posts

Posted 18 September 2012 - 06:34 PM

well, yeah, in my example. You could further enhance it as you see fit :)/>

#7 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 18 September 2012 - 06:39 PM

While a valid suggestion, it is not required to enable use with monitors. If output is redirected, the term functions automatically refer to the correct location.

#8 GopherAtl

  • Members
  • 888 posts

Posted 18 September 2012 - 06:44 PM

true, but it is requried to display to terminal and monitor from one program withouth redirecting the terminal all the time. Ex, monitor can be dedicated status display while terminal shows log and command input area. Certainly there are more sophisticated solutions possible, but simple isn't necessarily bad. :)/>

#9 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 18 September 2012 - 06:49 PM

Actually, I agree with GopherAtl, since I use that very function to set up my Master Control System monitor output. It runs the monitor while simultaneously running the terminal. So I think I will have to add monitor support. This gives me a few ideas for more functions as well.

#10 KaoS

    Diabolical Coder

  • Members
  • 1,510 posts
  • LocationThat dark shadow under your bed...

Posted 19 September 2012 - 05:35 AM

all that I would do in this situation is term redirect and use term.native.command for the local changes

#11 cheekycharlie101

  • Members
  • 231 posts

Posted 21 September 2012 - 07:25 PM

cant get it to work :)/> can someone help me out with this?

#12 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 21 September 2012 - 07:27 PM

  • Is it in your APIs folder?
  • How are you calling back to it?
  • If not in your APIs folder, where?


#13 cheekycharlie101

  • Members
  • 231 posts

Posted 03 October 2012 - 05:58 PM

Hey, i was using your write api a while ago. but now ive forgotten. can you please help me out.
thanks -Cheeky

#14 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 03 October 2012 - 07:22 PM

I have updated a list of function calls in the OP, and how to call to them properly, if you don't understand the code.

#15 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 09 November 2012 - 01:07 PM

I added a new function:
smartWrite.limitRead()
Now you don't have to have the read() or io.read() functions delete the end of your masterful ASCII art when you need to collect a string from the user!

#16 Cross_Sans

  • Members
  • 122 posts
  • LocationFrance

Posted 18 February 2016 - 01:47 PM

I'm so sorry uping this post, i don't watched the time :(

Edited by Redall, 18 February 2016 - 01:48 PM.


#17 Dahknee

  • Members
  • 1,808 posts
  • Location/home/da

Posted 18 February 2016 - 02:21 PM

View PostRedall, on 18 February 2016 - 01:47 PM, said:

I'm so sorry uping this post, i don't watched the time :(/>

Don't be! I have been looking for this type of thing for ages now, well the limitRead function anyway!!! So thank you! Just saved my day!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users