LC to C# conversion

Want to talk about something that isn't covered by another category?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Xero
Posts: 152
Joined: Sat Jun 23, 2018 2:22 pm

LC to C# conversion

Post by Xero » Mon Mar 13, 2023 3:30 am

Hi All...
I have a working stack in LC that I want to translate into C# language.
I am currently trying to upskill my C# knowledge (not hard since it's almost non-existent!) to do it myself, but time is getting at me.
What would be the best way to translate the LC stack into a working C# code?
Thanks in advance.
XdM

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: LC to C# conversion

Post by dunbarx » Mon Mar 13, 2023 3:54 pm

Whew.

I do not know C#, but I bet the answer to your question is to learn that language, and write the required code from scratch.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9578
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: LC to C# conversion

Post by dunbarx » Mon Mar 13, 2023 3:56 pm

I suppose you can use the "flow" of logic from your LC version to guide you, but I bet that is the only thing that will "translate" over.

Craig

Xero
Posts: 152
Joined: Sat Jun 23, 2018 2:22 pm

Re: LC to C# conversion

Post by Xero » Tue Mar 14, 2023 1:50 pm

Thanks Craig...
I guessed as such. The only problem being that I don't have access to the same community as I do here. Ask a question here, get a good answer, answer a question out there, get a blank stare...
So learn on I will I guess!
XdM

jiml
Posts: 336
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: LC to C# conversion

Post by jiml » Tue Mar 14, 2023 6:13 pm

Write an LC handler and ask ChatGPT to convert it to C#.
If it works build on that.

Worth a shot.

stam
Posts: 2633
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: LC to C# conversion

Post by stam » Thu Mar 16, 2023 8:03 pm

That's an interesting notion - but how would that work?
LiveCode is not an OOP language like C# - there is no concept of classes, inheritance etc. LC is not typed, but C# is. The list of differences is vast - which means the way you code will be vastly different.

In fact that's a big dividing line between xTalks and most other modern languages - so much so that people coming from the other side of the fence really struggle with LC in spite it being so much simpler.

You might be able in broad terms apply an algorithm in some circumstances to a C# function but at best it would be suboptimal... and you almost certainly won't be able to create the equivalent of a stack in C#

I think you're probably better off just learning C# from scratch and not draw parallels from LC - everything about C-style languages (especially OOP ones) is so different that you can't really apply the same logic.

For comparison of algorithms between C#, LC or in fact almost any language, see here: https://rosettacode.org/
This site lists various algorithms to be solved and people have submitted solutions for hundreds of languages, including LiveCode
For solutions using liveCode see here: https://rosettacode.org/wiki/Category:LiveCode
pick an algorithm and see how it's solved in LC and C# (or any other language)

HTH
Stam
Last edited by stam on Fri Mar 17, 2023 10:57 am, edited 1 time in total.

Xero
Posts: 152
Joined: Sat Jun 23, 2018 2:22 pm

Re: LC to C# conversion

Post by Xero » Fri Mar 17, 2023 4:34 am

Thanks Stam,
I think you poignantly summed up all of my troubles in trying to code C# straight off my LC file.
LC is so simple, it's like telling my 5 year old nephew what to do. C# has a completely different starting point and path. The logic doesn't translate well.
I have looked through Rosettacode- it's a great site for anyone wanting to see how different things are, but a bit useless when it comes to translating from one language to another, based on what has just been said. It's interesting to see how one language can code an algorithm in 2 lines, while another may take 10-20 or more lines. What I find annoying about C# is the need to define every variable, while in LC, you just dump stuff in a variable, and don't worry what it is- integer, decimal, letters, combinations, booleans, etc. And consequently, what I do in LC to just make up something and dump different things in it at different times just is not an option!
Sounds like I will need to learn some C# and see if I can make it work and compare at the end!
XdM

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9285
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: LC to C# conversion

Post by richmond62 » Fri Mar 17, 2023 7:56 am

Well, a Q & D web-search shows that one can be snowed under with teach-yourself resources for C#,
so 'all' you need is TIME and quite a bit of self-discipline.

Good Luck.

stam
Posts: 2633
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: LC to C# conversion

Post by stam » Fri Mar 17, 2023 10:46 am

Xero wrote:
Fri Mar 17, 2023 4:34 am
What I find annoying about C# is the need to define every variable, while in LC, you just dump stuff in a variable, and don't worry what it is- integer, decimal, letters, combinations, booleans, etc. And consequently, what I do in LC to just make up something and dump different things in it at different times just is not an option!
That's the norm for most languages - because the errors in code (passing a string when expecting a number etc) can be caught early by the compiler - so almost all compiled languages are strictly typed. It's only in more recent times that even optional variables (which may contain a value or not) are a thing - something we take for granted in LC... Languages like Swift can infer a type so you don't have to declare it's type at the start (ie you can just type var x = 10 and it will infer it's an integer and put '10' into it), but you can't then change the type of data that variable contains - trying to put a string into x will then generate an error...

Typeless languages like LC give more flexibility, but that comes with increased risk of run-time errors unless you check type (eg if myVariable is a number then...) which is safer but arguably makes the code more tedious...

Like you, I prefer LC for the speed of coding; but compiled languages produce a lot faster apps and platform specific languages (like C# on Windows and Swift on Mac) have many APIs for interacting with the OS that LC lacks...Perhaps once LC released complied scripting the speed difference will be less noticeable...

Above and beyond typing though, the conceptual differences between proper OOP languages and LC are huge. But learning is fun ;)

NoN'
Posts: 75
Joined: Thu Jul 03, 2008 9:56 pm
Location: Paris
Contact:

Re: LC to C# conversion

Post by NoN' » Mon Mar 20, 2023 2:04 pm

I'm getting away from the subject of this thread, but maybe this is the way to get back to it.

I've been wondering for a long time - probably very naively - about "inheritance" in Livecode.
We regularly read that there is no inheritance in LC. But can't/shouldn't we consider that the "start using" command constitutes a declaration of inheritance?
The called stack then becomes the base class and the calling stack becomes the derived class?

Is this an absurd remark (I'll totally assume so)?

Renaud

PS : thank you very much, Stam, for the link to rosettacode

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7214
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: LC to C# conversion

Post by jacque » Mon Mar 20, 2023 5:14 pm

I think library stacks are more a product of the message path. But many properties do inherit, like colors, text properties, and others. It's hard for me to decide where the line is between the message hierarchy and inheritance.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

NoN'
Posts: 75
Joined: Thu Jul 03, 2008 9:56 pm
Location: Paris
Contact:

Re: LC to C# conversion

Post by NoN' » Tue Mar 21, 2023 1:08 am

I wasn't necessarily thinking of library stacks, but stacks that are designed for one project and can be called upon for another project for example.
I think this process is rarely used with LC to avoid having to rewrite code (?).
But I also agree that the limit is difficult to define between inheritance and message hierarchy.
In the meantime, this would be one less argument for those who think that LiveCode doesn't behave according to the modern programming canons.

By the way, it is while seeing Python coding that this analogy was suggested to me

Xero
Posts: 152
Joined: Sat Jun 23, 2018 2:22 pm

Re: LC to C# conversion

Post by Xero » Tue Mar 21, 2023 1:54 am

The project this question was in regards to has to do with image manipulation, particularly the aRGB channels of a bitmap image. Looking in to it so far, the methods are completely different for LC and C#. For example, in LC, you load the data of the bitmap into a variable and pick through it, each 4th item for any given channel. In C#, you go to a pixel via the X,Y system. So in LC, line 1, pixel 2's red channel is 5th or 6th (I can't remember if a comes first or last...) item in the data of the image. In C# it's nPixelR= 2,1.R; Meaning that the way you access the pixel is different and the way you access the channel is different. So conversion directly is downright impossible in this kind of occasion...
XdM

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3990
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: LC to C# conversion

Post by bn » Tue Mar 21, 2023 10:02 am

Hi XdM,

In LC it is ARGB (alpha, red, green, blue) that describes a pixel of an image. All pixel are in imageData. However if you want to change the alpha value of a pixel in LC you use the alphaData of an image. Alpha data is one byte per pixel, 0-255.

Manipulating alphaData in LC is considerably faster than manipulating imageData since it is only a quarter of the size of the imageData.
Depending on the number and the size of the images you want to change and the kind of changes you want to perform on the alphaData LC could be an option to do this.

In my experience manipulating the alphaByte of imageData does not affect the transparency of the the image. Only when using alphaData you can change the transparency of a pixel.

Hermann (-HH) did a lot of work using javascript and the browser widget to speed up image manipulation in LC. But unfortunately I don't speak javascript.

Of course this all depends on what you want to achieve by changing the alpha values of the image.

Kind regards
Bernd

Xero
Posts: 152
Joined: Sat Jun 23, 2018 2:22 pm

Re: LC to C# conversion

Post by Xero » Tue Mar 21, 2023 10:46 am

Thanks Bernd, but the OP was in relation to a set of code that I want to give people as part of a game, so would need to be run easily, and downloading LC and running it etc. didn't fit the bill, so I have chosen a more widely used language that can be executed online with an emulator. The apps that I built to do these jobs I built in LC because it's a little more Xero-friendly to code with. If it were only me, I would be using LC, but as i's for other, unknown people, I have had to go a different way.

Post Reply

Return to “Off-Topic”