Annotation/Registration for Flexible Code

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
EliterScripts
Citizen
Posts: 85
Joined: Sat Oct 25, 2014 7:07 pm

Annotation/Registration for Flexible Code

Post by EliterScripts »

So I am creating my game, which piggybacks off of the LOVE2D physics engine. I'm currently programming a system that takes the world and turns it into a string so that it can be given to the client and brought from a string back into programming code again.

I wanted to take some ideas I saw in Java and apply them to Lua. I'm no Java expert, but I saw that Java supports annotations, which are NOT comments, which can somehow be fetched and searched for in other pieces of code. My extent of Java knowledge is printing "Hello World" and programming a simple SpongeForge Minecraft plugin.

Let's say I have items in the game. Since I want my game to be welcoming to mods, I don't want to lock my code into just registering "vanilla" items. So one approach is to have a file hard-coded to load in all the vanilla mods. The other method I see is to search files within the program for indicators for item load functions (i.e. functions that call the function that registers items, so then that mechanism can call the item function when the game needs it).

In java it looks something like this:

Code: Select all

import blaw.blaw.loadItem;
import blaw.blaw.spawnItem;
import blaw.blaw.useItem;

public class gun{

@loadItem("gun")
void loadItem(){

}

@spawnItem("gun")
void spawnItem(){
}

@useItem("gun")
void useItem(){
}

}
The annotations above start with the "@". I wanted to ask if there is anything close to what I'm looking for, and what best code practices I could use to implement something where I don't have to hard-code what items to register.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests