-
Notifications
You must be signed in to change notification settings - Fork 0
Lib creation
First thing to know, your lib has to be coded in Python.
If you use any external Python library, tell me, and I'll add them to the setup.py
.
Then, keep in mind that every lib is run from the same folder as main.py
.
First, you need to create a Python file. This Python file follows the following conventions :
- It has to be a python file (extension
.py
) - The name has to be in lower case, without symbols or numbers except the underline character (
_
). - The name has to start by
lib_
. - The first line of the file has to be its version, with this syntax :
version = "<version>"
- The second line of the file has to be the lib type, and can be one of the following :
-
functions
, if the lib contains only functions ; -
variables
, if the lib adds only variables ; -
functions+variables
, if the lib adds both ; -
This one is currently unavailable !modifiers
, if the lib adds modifiers.
-
That's it for the rules, now, you can access some other things by different ways :
- If you want to access the current code line (the word
lib
has been removed at the beginning of this line), you can typevar_line
. But I recommend you to doline = var_line
and use the variableline
created. It works better. - If you want to access the number of the code line, just type
line_numbers
. - If you want to access the user's defined variables or create new ones, just type
VARIABLES_CONTAINER
. As for the last one, I recommend you to dovariables_container = VARIABLES_CONTAINER
and use this variablevariables_container
. Also, do keep in mind that this variable is a dictionary.- If you touched or modified any of the user variables, they won't be modified anywhere. If you want to modify them, use this code at the end of your code :
with open("var_transfer.json", "w") as transfer_file:
transfer_file.write(json.dumps(variables_container))
transfer_file.close()
Just to give my personal advice on how to decompose the code line, that is how I do :
if line.startswith("<first_word>"):
line = line.replace("<first_word> ", "", 1)
# And you keep going this way with each word.
If you want to detect the variables in the code line, do it this way :
if "{" in line and "}" in line:
variable = line[line.find("{") + 1:line.find("}")]
If you want to tell the user about an error, do it using the error()
function (Syntax : error(<line_numbers>, <error_type>, [message_to_the_user])
. Then, it is better to stop the program. To do it, just import the Python lib sys
at the beginning of your Python program and type sys.exit()
.
Little showcase of the error function :
error(line_numbers, "LibError", f"Variable required at this position, got \"{line[0]}\" instead.")
First, join the ACPL official Discord server (link here).
Then, go in the channel #lib-submitting and do as following :
- Introduce yourself
- Present your lib
- Upload the lib file And wait for my answer !
In most of the cases, the lib will be accepted and will be downloadable by anyone.