Jump to content



Recommended Posts



Greetings, Noveans! This is NQ-Ligo again,


Some time ago, we redesigned the Lua API of Dual Universe, introducing new features and opening up many possibilities. Today, we’re launching the next major update to the game’s Lua, addressing the remaining fundamental issues and adding numerous new features.


In this post, I’ll present some upcoming 1.4 changes to give you ample time to adapt your creations. I’ll walk you through the changes we're making to the backend, as well as some cool additions to the game’s Lua API.


Fundamental Changes


Let’s start with the fundamental issues we had yet to address in the game’s Lua.


- Update of the Lua Environment


To leverage the optimizations and basic improvements in the Lua environment, we have updated it to version 5.4.4. You can review the changes on the official website of the language (https://www.lua.org/manual/5.4/readme.html#changes. Still, please note the introduction of new features such as:

  • New generational mode for garbage collection

  • New attributes for variables (const and to-be-closed)

  • New implementation for math.random

  • New semantics for the integer 'for' loop

  • Optional 'init' argument to 'string.gmatch'

  • New function 'coroutine.close'

  • String-to-number coercions moved to the string library

  • New format '%p' in 'string.format'


- Replacement of the dkjson Library


For some time, we have been addressing performance issues with Lua systems. A significant factor related to these performance issues is the use of JSON. Thus, we reduced the use of JSON in favor of Lua tables. However, after consulting many of you, it appears that JSON is still widely used by our players. Hence, we decided to replace the dkjson library with the json.lua library (https://github.com/rxi/json.lua), a pure Lua library that is much more efficient.


We've added a compatibility patch to prevent your existing scripts from breaking.


- Boolean Type and Nil Support


Until now, booleans returned or used in the Lua API were treated as integers 0 or 1. While this may seem minor, it was crucial to resolve for several reasons, including performance and backend considerations.


Good news: we've now resolved this issue, allowing the Lua API to accept arguments and return real booleans! This will allow you to optimize your scripts.


Additionally, we've integrated nil. Until now, we could neither return nor accept nil as an argument. Again, while this may seem minor, resolving this issue allowed us to introduce the concept of optional arguments and optimize the Lua data stack. You will see its application in the additions we are introducing.


In addition to these visible fixes, we've made several backend improvements to the game's Lua binding. Consequently, we decided to use this opportunity to increase the instruction limit of the Lua environment (the limit that triggers the CPU OVERLOAD error). Starting from version 1.4, this limit will be increased from 2,000,000 to 10,000,000 instructions, accessible with the getInstructionCount and getInstructionLimit functions added to the Lua system API.


With this change in Boolean support, you will need to adapt your existing creations to ensure they continue to function as expected. We believe the benefits of these updates justify the effort and we appreciate your understanding and cooperation as we continue to improve the game's Lua environment.


Improvement of the Syntax Highlighting


We've enhanced the syntax highlighting in our code editor interface to simplify your coding experience. We understand that coding can be challenging, especially for beginners. That's why we took the time to create a straightforward syntax highlighting system to make coding in Dual Universe easier and more enjoyable.


While we've improved syntax highlighting, it isn't a full-fledged code analyzer. It's merely a tool to help you read and understand your code more easily. We aim to make coding more accessible and affordable for everyone, and we hope this update will contribute to that. The new system incorporates the coloring of APIs for system, unit, library, construct, player, and Lua operators.



Enrichment of the Lua Codex


We're thrilled to announce a new section in the Lua CODEX - the "Usage Example" section. This section provides detailed explanations and code examples to help you better understand how to use the functions within our API. It will be added to each function or event that requires further explanation.


We understand that learning to use a new API can sometimes be daunting, especially if you're new to coding. Therefore, we believe that providing examples, use cases, and deeper instructions on how to use the various functions in our API will help you better understand our game's API, making your coding experience more enjoyable.




Radar Data Pre-filtering


Despite our efforts to optimize and make the processing of radar data more flexible, particularly by integrating the getConstructs function to return the list of constructs in scope as a Lua table, we've considered and studied additional improvements.


Thanks to the integration of nil support in our Lua environment, we decided to improve the getConstructs function by adding the following optional pre-filters:

  • [bool] isMatching: True to filter out constructs with a matching transponder, false otherwise

  • [int] constructKind: The construct kind id to filter out constructs (Universe = 1, Planet = 2, Asteroid = 3, Static = 4, Dynamic = 5, Space = 6, Alien = 7)

  • [string] coreSize: The construct core unit size to filter out constructs ('XS', 'S', 'M', 'L', 'XL')

  • [bool] isAbandoned: True to filter out abandoned constructs, false otherwise


This filter is in the form of a table in the third argument of the getConstructs function. So you can, for example, filter:

  • {isMatching = true}, to list only constructs with a matching transponder

  • {isMatching = false, constructKind= 5}, to list only dynamic constructs with a non-matching transponder

As you can see, this filtering is combinable and optional, enabling you to filter the data you receive before processing it through Lua, allowing you to optimize your scripts.




We hope these updates and performance upgrades will improve your Lua experience in Dual Universe. There are still many other additions to the Lua API waiting to be discovered in this release. Happy exploring!

Link to comment
Share on other sites

getInstructionCount and getInstructionLimit functions -> This is realy great, thank you!


BTW, would it be a major hassle to add the line where we stopped when we get CPU OVERLOAD? Often time, we get that in special conditions where we end up with a infinite loop on the lua side, but they are not easy always to catch. At least, if we knew in which part of teh code we were looping, that would be great.


Anyhow, thanks for the update, keep up the good work!



Link to comment
Share on other sites

Now that this has been posted to the forum too, I'll just link my original question above, and add this: Please, provide an out-of-game codex. Until such a time that the in-game code editor can measure up to VSCode with Lua plugins, and use of du-luac, most larger projects will be coded outside the game while not even having DU running. You have a perfect place for this - your GitHub repository. You've made a good start with the API mockup, but it needs more work and up-to-date annotations, like in this PR that's been waiting review/approval since Sept 8, 2022.

Link to comment
Share on other sites

Those are actually really good news! Glad to see Lua receiving some love, and specially, now being able to track down how many instructions have been used, as this will allow for much more optimized code to be made!


@Yoarii from what I recall, there's this codex available online, but an official one would definitely do wonders!

Link to comment
Share on other sites

12 hours ago, Wolfram said:

@Yoarii from what I recall, there's this codex available online, but an official one would definitely do wonders!

Yeah, official documentation is needed.


Also, NQ, could you please publish the specifications for the JSON and config formats used to load Lua onto our constructs?

Link to comment
Share on other sites

Great news to see that LUA stuff still receives love. Limit increases are very welcome. What I wait the most for LUA is emitter/receiver fixes. Declared range of them should be granted reliably for LUA uses. Unfortunately elements get unloaded really fast right now, you basically need to stand nearby for them to work. This, in my opinion, kills whole idea. If element is connected to link network where receiver exists, it should be loaded when traffic within relevant channels is happening. If that element is PB, this PB needs to be able to run even if it is at max distance emitter/receiver can work.


General note. If you really still bet on user generated content, you need to make sure that it is in fact doable. VPT (one of the best tools in DU) alone is not going to cut it. For static shapes based content the largest issue is that people can't unseat their ships without restarting the game in more developed areas like D6 neighborhood (if you can fly in and land there without issue, if you can walk there while stuff is being streamed in without issue, there is no real excuse why people can't unseat without downloading the whole world first). If you want player created campaigns, missions, mini worlds, games, services, you need to provide ways to run relevant scripts without requirement to stand nearby and stare into involved PBs for them to attempt to do their work. 🤷‍♂️

Link to comment
Share on other sites

On 5/19/2023 at 7:24 PM, Leniver said:

Good news!

The editor could need a bit more love, like being able to "Ctrl+Z" to cancel last change.

You're not wrong, but I think the smarter move would be to embrace existing code editors instead of doing their own, as well as other tooling that already exists in the community.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...