# Lua may be getting axed, how many people care?

**URL:** <https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488>\
**Category:** The Lab\
**Created:** [March 4, 2017, 3:50pm UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488 "2017-03-04T15:50:28Z")\
**Posts on this page:** 7\
**Page:** 3

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [June 2, 2017, 7:59pm UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488/41 "2017-06-02T19:59:07Z")

</div>

None of these functions from catalua.cpp are exported to class\_definitions.cpp - this is intended.

```auto
// Registry containing all the game functions exported to lua.
// -----------------------------------------------------------
static const struct luaL_Reg global_funcs [] = {
    {"register_iuse", game_register_iuse},
    //{"get_monsters", game_get_monsters},
    {"items_at", game_items_at},
    {"choose_adjacent", game_choose_adjacent},
    {"dofile", game_dofile},
    {"get_monster_types", game_get_monster_types},
    {"get_item_groups", game_get_item_groups},
    {NULL, NULL}
};
```

---

<div class="post-metadata">

**Author:** ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)\
**Post date:** [June 4, 2017, 6:52am UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488/42 "2017-06-04T06:52:25Z")

</div>

> [@JT](#):
>
> [quote=“Kevin Granade, post:38, topic:13488”]“this is too much work”

The stuff that’s being externalised will continue to be externalised and genericised for re-use elsewhere, and I never for a moment suggested that any one person would be expected to shoulder the burden entirely. ;-)[/quote]  
I only referenced the binding overhead as a side note, the main issue is the 10,000+ lines of new LUA you’re proposing someone should create, with no benefit to the work other than “it’s the right way to do it”.

[quote=“JT, post:40, topic:13488”]The reason that dynamic exists is because of the lean and mean principle: building story mechanics into the main build involves an overhead that can slow or stifle the development process on both sides of the equation, especially in something as mutable as a story. While development is normally iterative, moving from one feature to the next except when feature creep obviates or breaks previous features or bugs are discovered, storywriting is normally recursive, continuously refining, revising, rearranging, deleting, expanding, and distilling existing pieces to build a more cohesive whole.

My assertion is that it is indeed necessary and the right thing to do because any kind of direct integration with the program code will naturally suffer from substantial “noise” as every last change is made, re-made, reverted, and re-re-made.[/quote]  
I’m not seeing where LUA is substantially lower-friction than C++, it still needs a build for testing and it still requires PRs, review, commits etc. The only thing you don’t need for LUA code is C++ expertise, which cuts bth ways because LUA expertise isn’t a given.

> [@JT](#):
>
> [quote=“Kevin Granade, post:38, topic:13488”]In either case, the solution is to get rid of the disfunctional integration and then bring it back when it is needed AND someone (frankly, not me, I have no idea how that sort of integration _should_ work) has a plan for supporting scripters other than “expose a bunch of internal game state to LUA”. Basic LUA integration is extremely simple (though it does add some complexity to the build process), so it’s fairly trivial to restore, it’s the infrastructure to expose engine internals to LUA that’s a PITA, and that’s what hasn’t proven successful.

I’ve heard about how easy Lua is to integrate compared to, say, Python; if it really is that easy then it won’t be a major loss, so long as it can come back in another form later on. It’d render anything I was contemplating moot, but all of that doesn’t even exist yet so it’s a literal zero-value loss (actually even a net benefit to me as it saves me some time, come to think of it, although I’ll lament not being able to do it ;-)).[/quote]  
It really is, the build support and code inclusion is a handful of lines, integration is completely dominated by language bindings.

> [@JT](#):
>
> If you do want a candidate for an improved architecture, all you really need is an event-driven system:

What I mean is less the bindings themselves, but more of an outline of what LUA’s role in the game is. For example the biggest no-brainer is NPC conversations, the binding necessary to support conversations are very minor. Stuff like that, and even then, not until we actually need it.

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [June 8, 2017, 6:43pm UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488/43 "2017-06-08T18:43:30Z")

</div>

Will it be a good reason to keep LUA if most of mapgen code will be transferred from CPP to LUA?

`mil_surplus` mapgen in LUA: [https://www.dropbox.com/s/3gn2p4sgmt5gdmz/cdda\_mapgen\_mil\_surplus.zip?dl=0](https://www.dropbox.com/s/3gn2p4sgmt5gdmz/cdda_mapgen_mil_surplus.zip?dl=0)

Please don’t afraid excess amount of loot - i didn’t add check for loot spawn chances yet.

---

<div class="post-metadata">

**Author:** ![kevin.granade](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/kevin.granade/32/1316_2.png) [@kevin.granade](https://discourse.cataclysmdda.org/u/kevin.granade)\
**Post date:** [June 8, 2017, 10:38pm UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488/44 "2017-06-08T22:38:43Z")

</div>

Nope, we’ve been signalling for months now that LUA is going away, and nothing compelling has surfaced to change that decision.

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [June 9, 2017, 12:23am UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488/45 "2017-06-09T00:23:23Z")

</div>

> [@Kevin Granade](#):
>
> Nope, we’ve been signalling for months now that LUA is going away, and nothing compelling has surfaced to change that decision.

(sigh)

Nevertheless - [Dropbox - cdda\_lua\_mapgen\_v2.zip - Simplify your life](https://www.dropbox.com/s/rlgitvrk9hoo49r/cdda_lua_mapgen_v2.zip?dl=0)

Four overmaps in LUA:

`s_pharm`  
`s_sports`  
`mil_surplus`  
`sub_station`

---

<div class="post-metadata">

**Author:** ![Chezzo](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/chezzo/32/429_2.png) [@Chezzo](https://discourse.cataclysmdda.org/u/Chezzo)\
**Post date:** [June 9, 2017, 1:01pm UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488/46 "2017-06-09T13:01:26Z")

</div>

Hey Zhilkin, could this work for the mod I wanted to do where:

The apocalypse continues to evolve as you explore with fighting pits, cannibal towns, and apocalypse churches.

Basically, I wouldn’t want them to generate in the first overmap, but I would want them to start generating when you reveal more overmaps. Possibly also only during later seasons.

---

<div class="post-metadata">

**Author:** ![Zhilkin](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/zhilkin/32/3749_2.png) [@Zhilkin](https://discourse.cataclysmdda.org/u/Zhilkin)\
**Post date:** [June 9, 2017, 1:31pm UTC](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488/47 "2017-06-09T13:31:05Z")

</div>

[quote=“Chezzo, post:46, topic:13488”]Hey Zhilkin, could this work for the mod I wanted to do where:

The apocalypse continues to evolve as you explore with fighting pits, cannibal towns, and apocalypse churches.

Basically, I wouldn’t want them to generate in the first overmap, but I would want them to start generating when you reveal more overmaps. Possibly also only during later seasons.[/quote]

There are four LUA callbacks, two of which are calendar-related:

[ul][li]`on_new_player_created` - called when starting the game (used in StatsThroughSkills mod)[/li]  
[li]`on_skill_increased` - called when player skill is increased (used in StatsThroughSkills mod)[/li]  
[li]`on_day_passed` - called once a day (at midnight)[/li]  
[li]`on_minute_passed`- called once a minute[/li][/ul]

It is possible to store player string variables which can be saved/loaded with the game.

```auto
    player = {
        parent = "Character",
        functions = {
            { name = "get_value", rval = "string", args = { "string" } },
            { name = "set_value", rval = nil, args = { "string", "string" } }
        }
    }
```

Calendar class fields are exported to LUA:

```auto
    calendar = {
        new = {
            { "calendar" },
            { "int" },
            { "int", "int", "int", "season_type", "int" },
        },
        by_value_and_reference = true,
        attributes = {
        },
        functions = {
            { name = "day_of_week", rval = "string", args = { } },
            { name = "day_of_year", rval = "int", args = { } },
            { name = "get_season", rval = "season_type", args = { } },
            { name = "get_turn", rval = "int", args = { } },
            { name = "increment", rval = nil, args = { } },
            { name = "minutes_past_midnight", rval = "int", args = { } },
            { name = "print_time", rval = "string", args = { "bool" } },
            { name = "print_time", rval = "string", args = { } },
            { name = "seconds_past_midnight", rval = "int", args = { } },
            { name = "is_night", rval = "bool", args = { } },
            { name = "seconds", rval = "int", args = { } },
            { name = "minutes", rval = "int", args = { } },
            { name = "hours", rval = "int", args = { } },
            { name = "days", rval = "int", args = { } },
            { name = "sunlight", rval = "float", args = { } },
            { name = "textify_period", rval = "string", args = { } },
            { name = "turn_of_year", rval = "int", args = { } },
            { name = "years", rval = "int", args = { } },
            { name = "sunset", rval = "calendar", args = { } },
            { name = "sunrise", rval = "calendar", args = { } },
        }
    }
```

All lua mapgen-related (like, `map:ter_set`) and other functions are usable during the game, not only on mapgen stage.

So it should be possible to store initial calendar values, calculate time difference once a minute or once a day and make some changes to the map once enough time is passed.

Still there are many limitations in LUA (or at least I didn’t find the way to find a solution):

[ul][li]lua generated buldings aren’t rotated automatically;[/li]  
[li]overmaps (displayed in the map) cannot be changed;[/li]  
[li]it is not possible to calculate the number of tiles the player have traversed;[/li]  
[li]bigger overmap coordinates are unknown.[/li][/ul]

[Previous page](https://discourse.cataclysmdda.org/t/lua-may-be-getting-axed-how-many-people-care/13488.md?page=2)
