Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua spike (placeholder) #3290

Open
wants to merge 49 commits into
base: main
Choose a base branch
from

Conversation

voronoipotato
Copy link
Contributor

This is @alexswan10k 's work, though they have decided to prioritize rust, I'd like to keep this PR #2509 available so that work may continue on it, and people interested can contribute to it. I personally would love to contribute, and have played with it some but haven't yet made meaningful contribution. I wasn't able to find the branch @alfonsogarciacaro was referencing in the pr so I just used main as a placeholder for now.

@voronoipotato
Copy link
Contributor Author

voronoipotato commented Dec 9, 2022

My end goal would be semi-human readable lua. Here's the style I'm aiming for for classes.

-- example object
 Account = {balance = 0}
    
    function Account:new (o)
      o = o or {}
      setmetatable(o, self)
      self.__index = self
      return o
    end
    
    function Account:deposit (v)
      self.balance = self.balance + v
    end
    
    function Account:withdraw (v)
      if v > self.balance then error"insufficient funds" end
      self.balance = sel

@voronoipotato
Copy link
Contributor Author

Need to merge and update. Then add objects

@voronoipotato
Copy link
Contributor Author

Personal life got a bit busy for a minute there, things have calmed down I'll put some effort in tonight. It would be really fun if we could mod games like noita (my fav) or others with F#.

type Expr =
| Ident of LuaIdentity
| Const of Const
| Unary of UnaryOp * Expr

Check notice

Code scanning / Ionide.Analyzers.Cli

Verifies each field in a union case is named. Note

Field inside union case is not named!
type Expr =
| Ident of LuaIdentity
| Const of Const
| Unary of UnaryOp * Expr

Check notice

Code scanning / Ionide.Analyzers.Cli

Verifies each field in a union case is named. Note

Field inside union case is not named!
| Ident of LuaIdentity
| Const of Const
| Unary of UnaryOp * Expr
| Binary of BinaryOp * Expr * Expr

Check notice

Code scanning / Ionide.Analyzers.Cli

Verifies each field in a union case is named. Note

Field inside union case is not named!
| Ident of LuaIdentity
| Const of Const
| Unary of UnaryOp * Expr
| Binary of BinaryOp * Expr * Expr

Check notice

Code scanning / Ionide.Analyzers.Cli

Verifies each field in a union case is named. Note

Field inside union case is not named!
| Ident of LuaIdentity
| Const of Const
| Unary of UnaryOp * Expr
| Binary of BinaryOp * Expr * Expr

Check notice

Code scanning / Ionide.Analyzers.Cli

Verifies each field in a union case is named. Note

Field inside union case is not named!
| Return of Expr
| Do of Expr
| SNoOp
| ForLoop of string * start: Expr * limit: Expr * body: Statement list

Check notice

Code scanning / Ionide.Analyzers.Cli

Verifies each field in a union case is named. Note

Field inside union case is not named!
src/Fable.Transforms/Lua/Fable2Lua.fs Fixed Show fixed Hide fixed
src/Fable.Transforms/Lua/Fable2Lua.fs Fixed Show fixed Hide fixed
src/Fable.Transforms/Lua/Fable2Lua.fs Fixed Show fixed Hide fixed
src/Fable.Transforms/Lua/Compiler.fs Fixed Show fixed Hide fixed
| Fable.StringConstant(s) -> Const(ConstString s)
| Fable.BoolConstant(b) -> Const(ConstBool b)
| Fable.UnitConstant -> Const(ConstNull)
| Fable.CharConstant(c: char) -> Const(ConstString(string c))

Check warning

Code scanning / Ionide.Analyzers.Cli

Checks if the `string` function call is type annotated. Warning

Please annotate your type when using the string function.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bug in IonideAnalyzers because I can't think of a different way to annotate it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nojaf Any idea what is reported here ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I can't believe I missed that in retrospect.

let transformOp = transformOp com

match expr with
| Fable.IdentExpr i when i.Name = "" -> Unknown "ident"

Check warning

Code scanning / Ionide.Analyzers.Cli

Verifies testing for an empty string is done efficiently. Warning

Test for empty strings should use the String.Length property or the String.IsNullOrEmpty method.
@voronoipotato
Copy link
Contributor Author

next TODO is making type parameters either go away or do something useful

@voronoipotato
Copy link
Contributor Author

I didn't even realize this while working on it but this would be actually quite nice for neovim scripting....

@MangelMaxime
Copy link
Member

It could indeed, only "problem" I see is that from my POV Vim people are often focused on performance.

So perhaps, they will not like having a dependency like fable-library which takes some "place". It is also true that most OSS user don't look at source code too so they would probably not be aware of that fact.

@voronoipotato
Copy link
Contributor Author

I do think a lot of F# I'd write for neovim probably would translate to relatively straightforward lua, and I might be able to trim the library to parts that are being used after compiling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants