I just want to ask about mod writting, from coding im mostly know C but my question is pure curiosity. I saw that mods are mostly written in json files, but i saw lua also and i heard that C also could work. And my question is, how program read those lua files, and how could write c, and overall how it reading json exacly. I just want to know that, if someone can explain me ill be much gratefull
Adding or editing JSON.
The vast majority of the data dda handles (item definitions, crafting recipes, monster definitions, map generation templates, martial arts styles, mutations) is actually defined as json files. How this works is that there is some code written in c++ that loads the json entities and turns them into data and logic that can be used by the game engine. There are only certain things you can adjust about a JSON entity, because the code that reads it has to be written in such a way that it can apply that data to an entity of that type.
Implementation-wise, there are two components to this. First we have a JSON library that was written for dda that can parse and emit JSON. Secondly there is code for each kind of entity that reads JSON entries and turns them into game logic.
Adding or editing LUA.
LUA is a programming language that is designed to be embedded in other programs. There are various parts of dda that can accept LUA as an input, usually as part of some JSON entity. In theory, any behavior can be specified by LUA, but in practice, each piece of functionality that a piece of LUA can exercise has to have supporting C++ code. As a result, there are only a few places where LUA can be injected into the code, making it difficult to work with.
Two questions:
1.In what place of c++ code exacly json is loaded into game ?
2.Is in that same manner like json, lua is loaded ? Becouse i saw mods where in one catalog was and lua and json files, there cant be just one big json file ? And why that lua is not good for implement like json exacly ?
Each type has its own loader function. They are defined in relevant files (say, item_factory.cpp covers item loading), then assigned to json types in init.cpp. That is, which function is called depends on “type” field of the json.
Many jsons use a structure called generic_factory (in generic_factory.h) to store the loaded values.