[DEPRECATED] From Lua to C#

I started working on a guide that should help gmod Lua developers to start coding C#.

If there are any developers who are familiar with both Lua and C#, I encourage you to contribute to this article to make it somewhat complete and useful before S&box gets released lmao.

Also if you have any tips or comments you’re welcome to give them in this thread, I will appreciate it.

19 Likes

I would say… instead of pitting them against each other - which is redundant because we’re switching either way… maybe show some code examples? One in Lua and one in C#?

16 Likes

Yeah, the best way to explain something is give an example.

1 Like

I think it’s generally important to also put certain concepts in a written form other than just showing examples (i.e. unsigned and signed numbers) since you don’t handle those at all in Lua but the guide doesn’t really explain any of those aspects anyways at this point in time.

1 Like

Yeah that’s probably a good idea. A few lines of code are more illustrative than paragraphs of text. I’m afraid explanation comments are still required since some things won’t be obvious from the code alone.

Not all differences can be described in code though, like the inner workings that need attention or some general tips and patterns. Many things that are present in C# are missing in Lua at all, so introducing them to a beginner would also require some explanation code aside.

What do you think?

2 Likes

I don’t think a guide like this is going to be very useful, at least at the moment.

That isn’t to say that it’s a bad idea though, having articles describing how to transition from Garry’s Mod to S&Box (Instead of specifically moving from Lua to C#) could be really helpful. It’s just that it feels a bit too early since there are still a lot of things that are still being worked out.

It isn’t meant for easier

transition from Garry’s Mod to S&Box

It’s for Lua -> C# transition, without any details regarding Garry’s Mod or S&Box API.

There’s almost nothing at the moment but I’m planning to populate this guide with some examples of how you can achieve certain things you’re used to do in Lua using C#. This will help developers that aren’t familiar with many programming languages other than Lua not to try doing things “the Lua way” and introduce them to “the C# way”. That’s the idea, at least.

I don’t think the aim should be to tell them every concept, it should be to ease them into it. Simple common concepts.

  • ints
  • floats
  • strings
  • How do I define a function
  • How do I do an if block
  • How do I do a for loop
  • How do I do a foreach loop

It should be just be showing how their knowledge of Lua translates to c#. A foot in the door. If you do more all you’re showing them is how little they know.

11 Likes

I can’t deny that shortly after I wrote just a few lines about one small thing the article quickly became looking TL;DR in some sense.

If I’ll proceed describing everything in such detail it’ll just end up being too big and not many people will feel brave enough to go through it.

I’ll try shrinking it down to just examples of how to do this and that with a few short comments when needed.

1 Like

Might also be good to give some introduction if barebones at best into OOP. Some coming out of Garry’s Mod might have zero clue how that works, or have only worked with tables as classes.

2 Likes

Uhh, also, what do you think about the whole intro part on why C# was considered and such, should it be left in or removed?

One way it could be structured better is to unify the two sections that talk specifically about Lua and C# into one section, titled something along the lines of “Why does S&Box use C# instead of Lua?”.
The title “Why is C# good?” sounds like something one could easily disagree with.

2 Likes

I’d delete the lot and act like the reader can only read code

4 Likes

Cleaned up the article for now not to call anyone on making changes to it while I’m working on it on the background.

Any suggestions are still appreciated in this thread.

how classes interact with eachother, the point of static classes, how to extend classes, what structs are used for, those are some of the more confusing stuff i encountered

What is the scope of this article? Do you want to teach them the whole fundamentals of OOP, or just simply explain it to them in brief and let them do their own homework?

The transition between Lua -> C# isn’t that straight forward, there’s a lot of concepts to cover that don’t translate that clearly between an embedded scripting language like Lua and a strongly typed, object oriented and component-oriented language such a C#.

People already are strugging with Lua, now imagine teaching them how to transtition to C# and having to tell them “Hey actually, in C# you can’t assign a String to a float variable!”, they’d just look at you like a moron and say that Lua is better because it’s possible in Lua!

To be fair, I don’t think a text-based wiki tutorial is the way to go, instead, I’d recommend creating video tutorials aimed at people coming from Garry’s Mod Lua to S&box C#, teaching them the language there, the necessary concepts and so on, and the wiki post would be an index of all the good research material and tutorials they could use. I find that beginners learn much better visually rather than staring at a wall of text and code.

Like, link this to a green person:

And watch them turn pale - If this was a video, you would be able to break it down better bit by bit without necessarily holding their hand too much.

TLDR: Video tutorials and an wiki-page index aiming beginners at those tutorials and learning material is the way to go for me, personally.

EDIT: Of course, you could still create tutorial series for people who aren’t completely green to programming, how they’d use S&Box-specific concepts. For example, hooks in Garry’s Mod Lua, network library etc. are unique to Garry’s Mod, so naturally, showing how to interact with those systems to people that already know how to code would be beneficial.

4 Likes

A series of video tutorials is obviously a good thing, it requires much more effort though. I could create such a series in theory but if done properly it will take weeks and months.

There’s already a ton of great material on C# itself, you can learn all the details on your own. My aim is just to help people coming from gmod to get started, it won’t be a complete C# course. I hope that answers your question about the scope of it.

Updated the page a little. What do you think about such way of structuring it so far?

I’m not sure how I feel about Top Level coming so soon, although it is really important to understand why certain top-level expressions won’t call.

Maybe you can show an example of THIS WON’T CALL and THIS WILL CALL first, and then explain why?

Here’s lua code we want to make
Here’s the wrong way to do it
Here’s the right way to do it

Now this is why the wrong way won’t work

It kind of introduces them to the new concepts moving from lua

It also comes to question of: Should we have a tutorial exist for people transitioning or for all new coders? Some of that might be better offloaded to the newbie section

2 Likes

What about people semi familiar with both who want to quickly get up to speed and become familiar with “the right way to do it”? It’s easier to come back and look at an article than sift through a video series. I think there should be both a video series and a wiki article covering the most important stuff. I myself have only scratched the surface of c# and learning about what private and protected meant, and how to use namespaces really opened my eyes. To conclude. I prefer articles, but I think both articles and videos should exist for people shifting from lua to c#, and also for total noobs.