Skip to content

Lib creation

TheAssassin edited this page Jun 9, 2020 · 14 revisions

How to create an ACPL library

Table of contents

  1. Things to know
  2. How to create your lib
  3. How to publish your lib

Things to know

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.

How to create your lib

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 ;
    • modifiers, if the lib adds modifiers. This one is currently unavailable !

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 type var_line. But I recommend you to do line = var_line and use the variable line 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 do variables_container = VARIABLES_CONTAINER and use this variable variables_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.")

How to publish your lib

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.

Clone this wiki locally