Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relation between Lua and C?

Tags:

c

lua

I am on an internship in a software company in a few weeks to figure out if I should start an apprenticeship as a software programmer. I have some (very) basic experience with Lua through gaming, which I stated in the resume for the internship, and they told me that they have a project where I could build on that experience. So I decided to get some more knowledge and fiddle around with Lua - leading me to this question.

I know Lua is a scripting language, and that it is often embedded in C programs. From what I understand Lua itself is written in very basic C and also has its own interpreter if used stand-alone. If that is the case, is it correct that:

No matter if I use Lua stand-alone or embedded in a C-Programming environment, underlying it will always use C-Code?

And since it is a scripting language, what I do with commands in Lua is basically accessing and commanding underlying C commands, as in telling C what to do?

like image 621
Curt Dukis Avatar asked Oct 15 '22 09:10

Curt Dukis


1 Answers

No matter if I use Lua stand-alone or embedded in a C-Programming environment, underlying it will always use C-Code?

C is ordinarily a compiled language, so at runtime the C source code for Lua is not relevant any longer. But the machine code derived from that C source code will always be involved in executing your Lua code, so in that sense yes.

That does not necessarily mean that you need to know anything about C to write Lua code, however.

And since it is a scripting language, what I do with commands in Lua is basically accessing and commanding underlying C commands, as in telling C what to do?

Calling Lua a "scripting language" has more to do with the form of Lua code and the inspiration for its creation than it does with how Lua works. Notwithstanding any standalone interpreters, it is designed to be embedded in programs, for use in scripting behaviors of those programs. Certainly all of that is implemented in C, but as a Lua programmer, you should not think of it as Lua wrapping corresponding C functions.

Indeed, as a Lua programmer, you probably don't need to think about it at all. If you do think about it, however, then a better model is that a Lua-based scripting environment wraps program data and behaviors in a program-specific way.

like image 64
John Bollinger Avatar answered Oct 20 '22 00:10

John Bollinger