Difference between revisions of "Blitz:OS Calls"

From Amiga Coding
Jump to: navigation, search
(Created page with "OS calls use the Amiga API directly, ensuring compatibility with the operating system and the ability to use the techniques recommended by official SDK guidelines. The Amiga A...")
 
m (Using OS Libraries)
Line 9: Line 9:
 
<code>Execute_ "SYS:Prefs/Font", 0, 0</code>
 
<code>Execute_ "SYS:Prefs/Font", 0, 0</code>
 
This tries to run the program given in the quote marks.
 
This tries to run the program given in the quote marks.
<code>success = Execute_ ("SYS:Prefs/Font", 0, 0</code>)
+
<code>success = Execute_ ("SYS:Prefs/Font", 0, 0)</code>
 
This is the same call used as a function instead, which allows the result to be saved. For many calls, the result is a way of determining if the call was completed successfully or not. It also usually contains important information if successful which would be required later, such as file handles. Brackets must also be placed around the parameters to treat a call as a function.
 
This is the same call used as a function instead, which allows the result to be saved. For many calls, the result is a way of determining if the call was completed successfully or not. It also usually contains important information if successful which would be required later, such as file handles. Brackets must also be placed around the parameters to treat a call as a function.
  
 
If a function is treated as a statement, the return value is discarded. If a statement is treated as a function, the return value is 0.
 
If a function is treated as a statement, the return value is discarded. If a statement is treated as a function, the return value is 0.

Revision as of 13:22, 7 August 2015

OS calls use the Amiga API directly, ensuring compatibility with the operating system and the ability to use the techniques recommended by official SDK guidelines. The Amiga APIs are designed to be simple enough to use with the C language and so some almost all examples you will find are written in C. Nevertheless, with the more advanced features of Blitz mirroring the equivalent C features (structs, pointers etc.), it is possible to do pretty much anything with the API that you can do with C.


The AmiBlitz include files are generally written using the OS calls, so using these includes will allow you to easily access the OS functions properly without having to get deep into the official SDK documentation and trying to figure out how to adapt the examples to Blitz code. However there are also times when accessing the API directly is the simplest or only option.


Using OS Libraries

Blitz includes direct calls for several of the key Amiga libraries already built in as keywords. To call a specific function in Blitz, the name of the call is entered with an underscore on the end. This underscore denotes a command directly called from a library, which prevents any clashes with Blitz keywords. The official SDK is the best place to reference the specifics of each library and call, but in general, in contrast to most built in commands, library calls can be treated as either a statement or a function by simply using the relevant syntax. For example: Execute_ "SYS:Prefs/Font", 0, 0 This tries to run the program given in the quote marks. success = Execute_ ("SYS:Prefs/Font", 0, 0) This is the same call used as a function instead, which allows the result to be saved. For many calls, the result is a way of determining if the call was completed successfully or not. It also usually contains important information if successful which would be required later, such as file handles. Brackets must also be placed around the parameters to treat a call as a function.

If a function is treated as a statement, the return value is discarded. If a statement is treated as a function, the return value is 0.