chevron_left chevron_right
Login Register invert_colors photo_library
Thread Rating:
  • 0 Vote(s) - 0 Average


filter_list Lunar Learn the Stuck Programming Language - Thread 3: Plugin System
Author
Message
Learn the Stuck Programming Language - Thread 3: Plugin System #1
Syntax();
Learn the Stuck Programming Language - Thread 3: Plugin System
Click here for Thread 1
Click here for Thread 2



Firstly, if you haven't read the first thread, or you need to download the Stuck interpreter, go here.

This is going to be a little bit of a shorter thread, as it will simply show how you can develop a plugin for Stuck and use it right away! I'm going to show you how a plugin file is created and formatted.

To start off, if you plan to use any Unicode symbols, i.e. anything outside of the standard ASCII range, you will need to add the following header to your file for it to save properly, as Python 2 does not support Unicode characters by default.

Code:
# -*- coding: utf-8 -*-

Alright, once you've done that, you should put in whatever imports are required. Then, there are four variables that will not be modified, that simply provide information to the Stuck interpreter. They are NAME, CREATOR, VERSION, and DESCR. These all must be in capital letters to work properly! It should be pretty self explanatory how you should fill these fields, but here's an example:

Code:
NAME    = 'Tutorial Plugin'
CREATOR = 'Shebang'
VERSION = '0.0.1'
DESCR   = 'A plugin made for the plugin system tutorial.'

The reason I've included this is so that those interested in contributing to the GitHub page with plugins can do so and have their work credited Smile It's also useful to make sure that all of your files are in appropriate directories. This can be tested by running the interpreter, and typing "plugin" into the console. It will print out all of the plugins it is able to access, in a format like this:

Code:
Tutorial Plugin - Version 0.0.1 - By Shebang
    A plugin made for the plugin system tutorial.

Now, you can design your functions! There is a general formula for how these are supposed to function, but you can generally get fairly creative with how these work. In general, any value your function uses should be popped off the top of the stack, as in removed, have the function be applied, then add back to the top the new value. The old value will NOT be stored. You should return whatever portion of the stack you want, in general the whole thing minus what you've popped off, plus the new value wrapped in a list. The stack will always be provided as a function parameter.

As an example, here's a function that adds the top 3 values of the stack and pushes the value.

Code:
def add_top_3(s):
    k = s.pop()
    l = s.pop()
    m = s.pop()
    return s + [k + l + m]

Finally, once you've finished making your functions, you should create a dictionary, which matches a specific character to the functions you've provided. This is pretty straightforward and obvious, but you CANNOT use any character that has already been reserved for a command, or is important in parsing strings (") or numbers (0-9.). Other than that, you're free to use what you want. The name of the dictionary should be CMDS, in all-caps just like the information variables. Here's an example dictionary for this test plugin we've made.

Code:
CMDS = { 'W' : add_top_3 }

And that's pretty much it! Here's what our whole plugin file would look like:

Code:
# -*- coding: utf-8 -*-
# Only needed if you have unicode characters, I don't in this case but it's an example :)

NAME    = 'Tutorial Plugin'
CREATOR = 'Shebang'
VERSION = '0.0.1'
DESCR   = 'A plugin made for the plugin system tutorial.'

def add_top_3(s):
    k = s.pop()
    l = s.pop()
    m = s.pop()
    return s + [k + l + m]

CMDS = { 'W' : add_top_3 }

Thanks for reading!
[Image: CDUAq9d.png]

Reply

RE: Learn the Stuck Programming Language - Thread 3: Plugin System #2
Loveing your tutorials man, keep up the good work.

Reply

RE: Learn the Stuck Programming Language - Thread 3: Plugin System #3
I'm really liking this framework. The programs really seem shorter and cleaner than their would-be python2 counterparts.

Reply






Users browsing this thread: 1 Guest(s)