Skip to main content

2 posts tagged with "Yuescript"

View All Tags

The Tale of Rewriting the Moonscript Compiler

· 4 min read
Li Jin
A Dora SSR developer.

tokyo moon

Moonscript: A Niche Language with a Twist

Moonscript is a fascinating programming language that compiles into Lua and runs on the Lua virtual machine. Its syntax and features draw inspiration from Coffeescript, offering a sweet spot between expressiveness and readability—minimizing code while maximizing clarity. It's particularly adept at handling frequently changing business logic, allowing developers to slash code volumes significantly when compared to native Lua—sometimes down to a third! This not only saves time but also reduces bugs and troubleshooting headaches. But perhaps one of its quirkiest features, as revealed by a seasoned developer in a Discord chat, is its dedicated global but modest-sized user base and its delightful Sailor Moon-themed aesthetic.

emotions embedded

Open Source and Free: A Challenging Sustainability

The creator of Moonscript has developed commercial sites like the indie game marketplace itch.io and the art-sharing platform streak.club using this language. To maintain stability, he paused the addition of new features and slowed down on fixing issues since 2017. Understandably, life's tough, and the creator has set up a GitHub sponsor page hoping for more support for his open-source efforts. It's unfair to expect continuous free contributions from anyone, after all.

Rewriting on My Own Terms

As a die-hard fan of Moonscript, I couldn't just stand by. The original Moonscript compiler was written in Moonscript itself, with a core parser built in C using a PEG grammar library to generate ASTs, which were then processed back in Lua. This was a resource-intensive process, particularly for large projects where dynamic loading of Moonscript code could cause noticeable lag. Additionally, the dynamic nature of Lua made it ill-suited for handling strict data types in ASTs—a typical weak point in dynamic language development.

So, instead of building on the existing codebase, I opted for a fresh start in my second favorite programming language, C++ (with Moonscript being the first, of course). This rewrite not only solved several unresolved issues but also reintroduced some long-missed programming features from other languages. Check out the new project here: Yuescript.

Transpilers for Lua and PEG Grammar

Nowadays, compilers that generate code in another programming language are more accurately called transpilers. Lua’s simple design allows for fast compilation with a one-pass recursive descent parser. With diverse programming preferences, many have ventured into developing transpilers from various languages like JavaScript, TypeScript, Lisp, C, Python, Go, and C# into Lua. This enhances Lua's capabilities, driven by aesthetic preferences, personalized needs, and advancing hardware that liberates computing power. Even Python’s creator once used a LL(1) grammar to ensure parser efficiency thirty years ago. With today's better hardware, more complex grammars like PEG that allow infinite backtracking for matches have become viable, improving parser flexibility and future language evolution.

The Advantages of C++ in Writing a Transpiler

Describing Moonscript as a macro system on Lua isn’t far from the truth, as many of its features are essentially syntactic sugar over Lua. The process involves three steps: parsing the code into a Moon AST, converting this AST into a Lua equivalent, and finally translating that into code. C++ shines in handling ASTs with its compile-time and runtime type checking, which minimizes errors significantly. Since C++17, the language has become even more powerful and expressive. For instance, the use of template metaprogramming allows us to ensure safety and efficiency:

// Checking if an AST node is either Exp or ExpList
if (item.is<Exp_t, ExpList_t>()) {
...
}

// Fetching the last matching node for a given AST structure
if (auto variable =
node->getByPath<ChainValue_t, Callable_t, Variable_t>()) {
auto varName = toString(variable->name);
...
}

// Handling different AST structures with a switch statement
switch (node->getId()) {
case id<While_t>(): {
auto while_ = static_cast<While_t*>(node);
...
break;
}
case id<For_t>(): {
auto for_ = static_cast<For_t*>(node);
...
break;
}
...
}

Yuescript in Action: More Than Just a Language

Initially, Yuescript was tied to an open-source game engine project, Dora SSR (https://dora-ssr.net ), aiming to elevate the capabilities of the Lua-supported engine with an advanced version of Moonscript. Along with the engine’s Web IDE, Yuescript also adds modest code completion and type inference features to enhance coding efficiency.

I particularly enjoy using Yuescript during Game Jams, brainstorming with teammates and then diving into coding without overthinking the design—a somewhat reckless yet fun approach to programming. Although we still integrate some programming design using Dora SSR’s messaging system combined with Yuescript’s functional style. You can see some of our frenzied Game Jam projects in Yuescript at Dora SSR's repository.

So, as a dialect of Lua's dialect Moonscript, Yuescript not only holds its ground in theory but has also been battle-tested in real applications within the Dora SSR project.

From Compiler, Game Engine to Handheld Console: My Journey in Indie Game Development

· 5 min read
Li Jin
A Dora SSR developer.

Introduction

Developing my own games has been a dream since childhood, particularly fueled by my extensive use of the Warcraft 3 World Editor. This sparked a fascination with game engines and development tools. As a student, I delved into programming and soon felt the urge to expand beyond just using various programming languages for development. I started maintaining a programming language called Yuescript, tailored for writing game logic. My learning journey in graphics led me to rewrite the Cocos2d-x as a learning project, which eventually evolved into the Dora SSR game engine. Later, as my love for handheld gaming consoles grew, I began collaborating on an open, programmable gaming device called the "Auspice Gear", aiming to achieve the ultimate digital freedom in gaming.

The Fun and Challenges of Game Scripting Languages

Multilingual Playground!

Multilingual Playground!

Programming in various languages is exhilarating, as each language offers unique programming philosophies and design principles. For scripting complex and dynamic game mechanics, I prefer using languages that are succinct and expressive. Yuescript, translatable to Lua, fulfills this need beautifully. Over time, as I developed more with my Dora SSR engine, I integrated languages like Teal (which adds static typing to Lua), TypeScript (for enhanced code hints and checks), JSX, and XML (for descriptive, componentized development). Each scripting language shines in specific game development contexts and seamlessly inter-operates through translation to Lua. Beyond Lua-based extensions, the Dora SSR engine also experiments with supporting diverse scripting languages via the WASM virtual machine, such as Rust and upcoming support for C++ and Go, balancing performance with runtime expansibility.

Innovating with Game Engines

Game creation at your fingertips!

Game creation at your fingertips!

While high-performance graphic rendering and complex scene construction are typically associated with game engines, as an indie developer and enthusiast, I believe many 2D games or those blending 2D and 3D effects can also offer highly creative and unique experiences. Ideally, devices for developing and running games should be unrestricted. Thus, Dora SSR was envisioned to provide an accessible and user-friendly environment, or even a full-fledged game development IDE, on as many devices as possible. Game development has become a part of my daily routine, allowing me to enjoy coding and debugging game features leisurely and sporadically, using whatever devices are at hand.

Dora SSR features a built-in Web IDE server within the game engine runtime, enabling code writing, running, and debugging directly on any terminal device via a web browser. This integration provides visual hints and access to various game development and resource management tools. Presently, Dora SSR supports game development on platforms like Windows, macOS, iOS, Android, and several Linux distributions.

Pursuing the Dream of a Free and Open Gaming Handheld

Open source everything?

Open source everything? Want it for both software and hardware!

Despite the progress, the pursuit of an unrestricted and open gaming development experience is far from over. As a veteran handheld gaming enthusiast dissatisfied with many commercial open-source handhelds, I envisioned a device not just for playing games but also for freely developing, running, and even distributing homemade games. Many manufacturers restrict programmability for profit, so with like-minded hardware enthusiasts, we developed the fully open "Auspice Gear", offering modular customization of its core components and design.

Auspice Gear + Dora SSR

Auspice Gear + Dora SSR

Returning to the Essence of Game Creation

An open-source indie game project

An open-source indie game project made by the community called 'Luv Sense Digital'

So, did I eventually make my game? Yes, though it's not entirely complete yet. Before the generative AI boom of 2020, we envisioned a future where AI played a central role in games—where humans, having their material needs fully met, engage in games to provide creative and intelligent data for AI training. This data, assessed by futuristic banks, determines an individual's monetary worth. The AI trained with this data helps with all aspects of material production, individual nurturing, and social management. This narrative reflects our ongoing quest to define ourselves through our creations rather than being defined by circumstances into which we were born.

If you're interested in our work on programming languages, game engines, gaming handhelds, or our game project, feel free to star our repositories or join our discussion groups. Although our projects are still in their early stages, they are continuously integrated and iterated upon, offering a glimpse into our progress and processes.

We warmly invite everyone passionate about game development to join us. Whether contributing code, providing feedback, or sharing our projects, your efforts help us collectively realize the dream of freely developing games.