samyeyo / LuaRT

Open source Windows programming framework for Lua
https://www.luart.org
Other
285 stars 17 forks source link

Question: is LuaRT to Lua what C++ is to C? #48

Closed Whoeza closed 8 months ago

Whoeza commented 1 year ago

Hi! I was wandering through the web in search for metatables and making Lua OOP (implementing polymorphism, inheritance, and encapsulation) for the n-th time, and I stumbled upon your framework. I checked your repository and it's all C code. I check your website and you have new syntax like Greet = Object {}.

Haven't you created a new language? A "Lua++" so to speak?

Cheers, Chuck

samyeyo commented 1 year ago

Hi Chuck,

It's a rather relevant remark, thank you for allowing me to clarify.

The LuaRT OOP library uses the same mechanisms as other Lua OOP libraries: metatables, but LuaRT enables object-oriented programming simply and instantly without depending on third-party libraries, hiding all the complexity behind.

Thus, LuaRT is Lua, but with batteries (the OOP part is an example of an out-of-the-box battery).

LuaRT C API, an extension of the Lua C API, allows the use of OOP mechanisms on both the Lua script and C API sides. There is no parser/lexer modifications (in fact the whole Lua source code is not affected at all) and as such, LuaRT is Lua.

Regarding the following syntax: Greet = Object {}

It is simply the possibility offered by Lua to call a function without parentheses using a table or a string as a single argument. In fact, this statement is equivalent to: Greet = Object({})

Regards, Samir

Whoeza commented 1 year ago

From your answer, I have the impression that everything you have done in C from the Lua C API, creating the LuaRT C API, could be done in Lua alone, because LuaRT is Lua; however, it would be a much less performant system than you have done in C.

Is that what LuaRT is? A framework written in C that defines OOP in Lua? I'm not familiar with this topic, so I'm not surprised if I'm not making sense.

And if it is possible to code the OOP paradigm with Lua alone, does it mean that one can obtain the OOP paradigm starting from a language that uses the functional paradigm? Implying that most differences between the two paradigms is "syntactical sugar", and the two are interchangeable and equivalent -- just different paradigms, in other words, different ways to say the same thing.

samyeyo commented 1 year ago

From your answer, I have the impression that everything you have done in C from the Lua C API, creating the LuaRT C API, could be done in Lua alone, because LuaRT is Lua; however, it would be a much less performant system than you have done in C. Is that what LuaRT is? A framework written in C that defines OOP in Lua? I'm not familiar with this topic, so I'm not surprised if I'm not making sense.

Yes you are right.

And if it is possible to code the OOP paradigm with Lua alone, does it mean that one can obtain the OOP paradigm starting from a language that uses the functional paradigm? Implying that most differences between the two paradigms is "syntactical sugar", and the two are interchangeable and equivalent -- just different paradigms, in other words, different ways to say the same thing.

The OOP C layer of LuaRT relies on the Lua C API and metatables, I don't think it can be used in another language if I understand your question.

Whoeza commented 1 year ago

And if it is possible to code the OOP paradigm with Lua alone, does it mean that one can obtain the OOP paradigm starting from a language that uses the functional paradigm? Implying that most differences between the two paradigms is "syntactical sugar", and the two are interchangeable and equivalent -- just different paradigms, in other words, different ways to say the same thing.

The OOP C layer of LuaRT relies on the Lua C API and metatables, I don't think it can be used in another language if I understand your question.

So, I understand that everything done in LuaRT can be written in Lua (and that you chose to use C API for performance goals). Does it mean I could recreate LuaRT by purely writing it in Lua alone? [^1] Follow-up question: does it mean that a functional programming language can code the object oriented paradigm within the language? (I already expect this to be the case, just asking for confirmation or negation)

[^1]: I ask because I wanted for a long time to make an OOP system in a Lua environment on which I could not load something like LuaRT; but if LuaRT is Lua and I can write it in Lua, then I could make an OOP system in the environment aforementioned.

samyeyo commented 1 year ago

So, I understand that everything done in LuaRT can be written in (and that you chose to use C API for performance goals).

Yes it should, but I choose C API implementation to be able to create instances from the Lua side and the C side, for LuaRT binary modules maintainers.

Does it mean I could recreate LuaRT by purely writing it in Lua alone?

No, because LuaRT framework relies on various Objects and instances, but developped in C to access Windows programming interface.

Whoeza commented 1 year ago

So, I understand that everything done in LuaRT can be written in (and that you chose to use C API for performance goals).

Yes it should, but I choose C API implementation to be able to create instances from the Lua side and the C side, for LuaRT binary modules maintainers.

Does it mean I could recreate LuaRT by purely writing it in Lua alone?

No, because LuaRT framework relies on various Objects and instances, but developped in C to access Windows programming interface.

Thank you for your time and answers. I have more questions.

1) So, by using C API, you implemented the Lua language, and by using WPF you have access to stuff that I could not access with pure Lua code?

2) What does WPF provide to you that is needed by LuaRT?

3) What does pure Lua lack that it cannot code a Lua-pure LuaRT-like framework?

samyeyo commented 1 year ago

So, by using C API, you implemented the Lua language, and by using WPF you have access to stuff that I could not access with pure Lua code?

No I did not reimplemented the Lua language, LuaRT uses the standard Lua implementation with an OOP layer. I don't use WPF either, just Windows API, that cannot be accessed from the Lua side.

What does pure Lua lack that it cannot code a Lua-pure LuaRT-like framework?

It lacks a FFI layer (that permits to call directly Windows API functions), but even with that it's a lot of work

Whoeza commented 1 year ago

Thanks again for your answers.

No I did not reimplemented the Lua language, LuaRT uses the standard Lua implementation with an OOP layer. I don't use WPF either, just Windows API, that cannot be accessed from the Lua side.

There you go! What I wanted to ask: (A) is it possible to code an OOP layer written in pure Lua code? I couldn't find the term to describe my question.

It lacks a FFI layer (that permits to call directly Windows API functions), but even with that it's a lot of work

Correct me if I'm wrong. I understand that:

(A) and (B) and (C) = true or false? :)

samyeyo commented 1 year ago

(A) = true (C) = false => I don't use any FFI layer, only pure C that interfaces with Lua through OOP