← Back to Lua Course | Chapter 1: Introduction | Lesson 6 of 7

Scripts चलाना और REPL

lua command से एक file चलाएँ, या interactive prompt में एक-एक करके lines type करें।

Scripts और REPL चलाना

बिना arguments के lua चलाना interactive REPL शुरू करता है, जहाँ हर line तुरंत execute होती है। lua script.lua चलाना एक file execute करता है, और extra command-line words global table arg बन जाते हैं। -e option सीधे एक snippet चलाता है, और -i एक script के बाद REPL में drop करता है।

Note: Lua 5.3 के REPL में आप इसकी value print करने के लिए =expression type कर सकते हैं।

उदाहरण: Running scripts and the REPL

bash
$ lua
Lua 5.3.6  Copyright (C) 1994-2020 Lua.org, PUC-Rio
> x = 10
> =x * 2
20
> os.exit()
$ lua hello.lua alpha beta
$ lua -e "print('hi')"
hi

⚠️ Run this in your own terminal or Node.js environment.

{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. बिना file के lua type करना और कुछ न होने की उम्मीद करना
  2. file name में .lua extension भूल जाना
  3. यह उम्मीद करना कि arg REPL के अंदर exist करेगा
चैप्टर सारांश
  • अकेला lua REPL खोलता है
  • lua file.lua एक script चलाता है
  • arg command-line arguments holds करता है
  • lua -e code की एक string चलाता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.