1. Home
  2. /
  3. Solar2d Typing Test
  4. /
  5. Lua Example - Simple Counter

Lua Example - Simple Counter - Solar2d Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Lua Example - Simple Counter — Solar2d Code

A simple Solar2D Lua script to increment and decrement a counter displayed on the screen.

-- main.lua
local count = 0
local counterText = display.newText("Count: 0", display.contentCenterX, 100, native.systemFont, 40)

local function updateCount(delta)
	count = count + delta
	counterText.text = "Count: " .. count
end

local incButton = display.newText("+", display.contentCenterX - 50, 200, native.systemFont, 50)
incButton:addEventListener("tap", function() updateCount(1) end)

local decButton = display.newText("-", display.contentCenterX + 50, 200, native.systemFont, 50)
decButton:addEventListener("tap", function() updateCount(-1) end)

Solar2d Language Guide

Solar2D (formerly Corona SDK) is a free, open-source, cross-platform 2D game and app development framework using Lua scripting. It focuses on rapid development and performance for mobile, desktop, and HTML5 applications.

Primary Use Cases

  • ▸2D mobile games
  • ▸Educational apps and interactive media
  • ▸Prototyping and game jams
  • ▸Casual games for iOS/Android
  • ▸HTML5 browser-based apps

Notable Features

  • ▸Lua scripting for all game/app logic
  • ▸Fast 2D rendering with hardware acceleration
  • ▸Physics engine integration (Box2D)
  • ▸Cross-platform support (iOS, Android, Windows, macOS, HTML5)
  • ▸Extensive plugin ecosystem for ads, analytics, and native features

Origin & Creator

Originally developed as Corona SDK by Ansca Mobile in 2009, it was later renamed Solar2D and made open-source in 2020.

Industrial Note

Solar2D is popular for rapid 2D mobile development, small-scale games, casual apps, and educational tools where lightweight Lua scripting and cross-platform deployment are valued.

Quick Explain

  • ▸Solar2D allows developers to create 2D games and apps using Lua scripting and a lightweight engine.
  • ▸It supports graphics rendering, physics, audio, input handling, particle systems, and native UI integration.
  • ▸Used by indie developers and small studios for mobile apps, casual games, and prototypes.

Core Features

  • ▸Display objects (sprites, images, shapes)
  • ▸Scene management via Composer
  • ▸Physics and collision handling
  • ▸Audio playback and effects
  • ▸Particle effects and GUI components

Learning Path

  • ▸Learn Lua scripting basics
  • ▸Understand display objects and physics
  • ▸Use Composer for scenes
  • ▸Add audio and particle effects
  • ▸Deploy to mobile and HTML5 platforms

Practical Examples

  • ▸2D platformer
  • ▸Casual puzzle game
  • ▸Endless runner
  • ▸Educational interactive app
  • ▸Top-down arcade shooter

Comparisons

  • ▸Solar2D vs Unity: lightweight 2D vs full 2D/3D engine
  • ▸Solar2D vs Defold: both Lua-based, Defold uses component system
  • ▸Solar2D vs GameMaker Studio: Solar2D open-source vs GMS paid
  • ▸Solar2D vs Cocos2d-x: Lua scripting vs C++/Lua hybrid
  • ▸Solar2D vs Construct 3: code-based vs visual scripting

Strengths

  • ▸Lightweight and fast for 2D
  • ▸Free and open-source
  • ▸Rapid prototyping and development
  • ▸Strong mobile deployment support
  • ▸Large plugin ecosystem for monetization and analytics

Limitations

  • ▸Primarily 2D; no 3D support
  • ▸Smaller community than Unity or Godot
  • ▸Limited advanced GUI customization
  • ▸Performance can degrade with very complex scenes
  • ▸Lua scripting required, not visual scripting

When NOT to Use

  • ▸3D or VR projects
  • ▸High-end AAA games
  • ▸Complex GUI-heavy apps
  • ▸Very large-scale games with thousands of objects
  • ▸Projects needing massive community marketplace

Cheat Sheet

  • ▸Display object = visual element
  • ▸Composer = scene manager
  • ▸Physics body = collision object
  • ▸Event listener = touch/gesture
  • ▸Module = Lua reusable script

FAQ

  • ▸Is Solar2D free?
  • ▸Yes - fully open-source.
  • ▸Does it support mobile?
  • ▸Yes - iOS and Android.
  • ▸Can it handle multiplayer?
  • ▸Yes - via plugins and network Lua code.
  • ▸Is it beginner-friendly?
  • ▸Yes - Lua scripting is easy to learn.
  • ▸Does it support 3D?
  • ▸No - primarily a 2D engine.

30-Day Skill Plan

  • ▸Week 1: Lua basics and Hello World
  • ▸Week 2: Sprites, touch events, physics
  • ▸Week 3: Scene management with Composer
  • ▸Week 4: Audio, particles, and GUI
  • ▸Week 5: Multi-platform build and optimization

Final Summary

  • ▸Solar2D is a lightweight, Lua-based 2D engine for rapid development of mobile and web games.
  • ▸It features fast 2D rendering, physics, audio, GUI, and plugin support.
  • ▸Open-source and free, ideal for indie developers and small studios.
  • ▸Best suited for casual, educational, and performance-sensitive 2D projects.
  • ▸Cross-platform deployment makes it versatile for mobile and HTML5 applications.

Project Structure

  • ▸main.lua - entry point
  • ▸config.lua - project settings
  • ▸scenes/ - Composer scenes
  • ▸images/ - sprites and graphics
  • ▸audio/ - sound and music

Monetization

  • ▸Mobile ads
  • ▸In-app purchases
  • ▸Paid app sales
  • ▸HTML5 ad-supported apps
  • ▸Game jams and prototypes

Productivity Tips

  • ▸Use Composer for scene management
  • ▸Modularize Lua scripts
  • ▸Profile memory and CPU early
  • ▸Use texture atlases
  • ▸Leverage plugin ecosystem

Basic Concepts

  • ▸Lua: primary scripting language
  • ▸Display objects: sprites, images, shapes
  • ▸Composer: scene management library
  • ▸Physics: collision and dynamics via Box2D
  • ▸Events: touch, accelerometer, timers

Official Docs

  • ▸https://solar2d.com
  • ▸https://docs.solar2d.com
  • ▸https://github.com/coronalabs/corona

More Solar2d Typing Exercises

Solar2D Lua Example - Moving ObjectSolar2D Lua Example - Touch DragSolar2D Lua Example - Simple ButtonSolar2D Lua Example - Fade In/OutSolar2D Lua Example - Simple PhysicsSolar2D Lua Example - Sprite AnimationSolar2D Lua Example - Timer EventSolar2D Lua Example - Simple SceneSolar2D Lua Example - Audio Play

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher