Lua and multi-paradigm programming: scope and capabilities

Despite having started learning programming with Pascal and C, after the jump to OO (C++, Java) I lost sense of the structured programming paradigm. I have started learning Lua and I have researched many tutorials, but all of them only cover basic operations and language features and capabilities. They feel more like a reference doc than a programmer’s guide.

Now, when trying to work with day to day tasks, how does one go through most common design patterns like observer, or multithreaded programming, creating UI elements and polling system calls for keyboard or sensors? Is it even feasible in this languages or you have to work with the C binding, libraries and low-level programming to get most stuff done? Do I get the Lua scope wrong?

Besides the reference doc (which is a good way to learn a small language IMHO), there’s Programming in Lua (PiL). It teaches both the language and the common idiomatic patterns.

About scope, Lua is a high level language. It allows you to quickly express algorithms and create structures. It’s also widely used as an extension language, to be embedded within an application.

There are many C modules available, both to add new capabilities (LPEG, LuaSocket, etc.) and to ‘bind’ to existing C libraries (databases, XML parsers, etc.), but Lua itself is a complete language, you’re not required to write C modules on day-to-day work.

About the “most common design patterns” do you mean the “Gang of Four” design patterns? (you mention the Observer pattern). If so, While really useful and written in a language-agnostic tone, many of these patterns make sense only in statically-typed, heavily OO languages like C++, Java, C# and a few others. With other platforms, some are unnecessary (like the Command Patterns, which becomes a closure when you have lexically scoped, first class functions), some others are applicable but result in widely different solutions.

About multithreaded programming: Lua itself is mostly single-threaded. There are several ways around this, but they’re not so heavily needed as on other platforms. A simple coroutine-based scheme is quick and easy to write and works perfectly in many cases. When not, the exact way to do multithreading depends a lot on your needs.

GUI: this is in the realm of a GUI library and not of the language. There are several available. Again, you can pick any one, or none at all. There are many things to do without GUIs (command line, application extensions, servers, etc)

Hardware integration: depends on the hardware. In most cases, there should be a C API and so you need a binding library, which is not hard to write (sometimes it’s just a 5-20 line C function for each API entry point)

1

Lua is, in many ways, very similar to Scheme: procedural with first-class and higher-order procedures, block-structured, lexically scoped with lexical closures, proper tail calls, use of a single pervasive data structure (list in Scheme, table in Lua) throughout the entire language.

The Scheme community has produced some extremely high quality programming books and tutorials, which are all more or less directly applicable to Lua.

  • How to Design Programs – An Introduction to Programming and Computing by Matthias Felleisen, Robert Bruce Findler, Matthew Flatt, and Shriram Krishnamurthi. They are currently working on a second edition, and after that, a second volume (How to Design Components).

  • Concrete Abstractions – An Introduction to Computer Science Using Scheme by Max Hailperin, Barbara Kaiser, Karl Knight.

  • The Little Schemer by Daniel P. Friedman and Matthias Felleisen

  • The Seasoned Schemer by Daniel P. Friedman and Matthias Felleisen

  • The Reasoned Schemer by Daniel P. Friedman, William E. Byrd and Oleg Kiselyov

  • Structure and Interpretation of Computer Programs by Gerald Jay Sussman and Guy L. Steele, Jr.

and many many many others.

One important difference between the two languages is that even though both are impure imperative languages, the Scheme community actually prefers a very purely functional, immutable, side-effect-free, declarative programming style than the Lua community. So, if you learn Lua via Scheme, your code might not be fully idiomatic Lua. I don’t think that’s a bad thing: first of all, functional programming is a good thing, and secondly, you already know imperative programming from your forays into Pascal, C, C++ and Java anyway.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật