Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
New Lua enhancements — Gideros Forum

New Lua enhancements

SinisterSoftSinisterSoft Maintainer
edited October 2017 in Code snippets
I've added a multi-dimensional array indexing with comma syntax patch by Mark Fieldman.

It modifies the parser to support multi-dimensional array indexing with comma syntax, i.e. m[1,2] is treated by the parser as being identical to m[1][2], thus allowing for code such as the following:
m = {[1]={}, [2]="foo"}
m[1,2] = "bar"
print(m[2], m[1][2], m[1,2])  --> foo  bar bar
m.foo = {}
m.foo.bar = "baz"
print(m["foo","bar"])         --> baz
I've also added some mutation operators:

+= add
-= sub
*= mult
/= div
%= mod
^= power
a=4
a+=1 -- a is now 5
a^=2 -- a is now 25
These will save a lot of typing and should be faster because the source variable only needs to be looked up once.
Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
https://deluxepixel.com
+1 -1 (+4 / -0 )Share on Facebook

Comments

  • This is neat. The operators need documenting too.becausr they're not standard? I always missed the ++ opertator personally, not sure if that can be added though. :)

    Likes: antix, Atavismus

    My Gideros games: www.totebo.com
    +1 -1 (+2 / -0 )Share on Facebook
  • It could be added, it's the same as +=1 though, would we then also have to add -- ?

    Besides, we have limited operator space I think (to fit in the bytecode), possibly right at the end.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • SinisterSoftSinisterSoft Maintainer
    edited October 2017
    The array stuff is good, you could load something like:
    map={{1,2,3},{4,5,6},{7,8,9}}
    print(map[2,3])  -- would print 6
     
    map[2,3]=12
    print(map[2,3])
    rather than
    map[2][3]=12
    print(map[2][3])
    Much easier for beginners and less typing.

    Likes: jdbc

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • Note: The mutation operators do a single assign, not multiple, so:
    a,b,c=1,2,3
    a+=1
    b+=1
    c+=1
    will work, but this won't:
    a,b,c=1,2,3
    a,b,c+=1,1,1
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Fantastico!

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • It should hopefully be in the next version (very soon). I've uploaded the changes to the repo for @hgy29. :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Even things like this will save a cycle or two:
    a+=b
    is the same as
    a=a+b
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • john26john26 Maintainer
    Can't do -- as it is a lua comment. Hence ++ doesn't make sense either
    +1 -1 (+2 / -0 )Share on Facebook
  • Yhaaarwh. Farewell my incremental ++ beauty.
    My Gideros games: www.totebo.com
  • One more thing to note:

    As you would expect, the right hand side of the operation is evaluated first, so:
    a=4
    a*=4+1
    print(a)
    will result in 20 being printed, not 17.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • YanYan Member
    edited November 2017
    What kind of enhancement is this ? Is this lua module ? Or this is only for Gideros ? I mean if my code been migratet does it might work on different lua platforrm ?
    vk.com/yan_alex
  • @Yan, just for Gideros AFAIK
  • @Yan, just for Gideros AFAIK
    Well, its very cool enhancement, but a little bit confusing as its a local language mutation, may be confusing

    vk.com/yan_alex
  • some say that it even has some advantages as it is harder to steal your code.

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • SinisterSoftSinisterSoft Maintainer
    edited November 2017
    Yes, it should be harder to steal your code as the produced bytecode is not the same as regular lua bytecode.

    The extra operators, fake thread system, etc that have added are also completely optional - The Gideros version of lua is source code compatible with Lua 5.1. Your source code from other systems will work fine if you are moving to Gideros.

    An enhancement to Gideros Lua a while back that made it have a universal 32/64 bit Lua bytecode. This means that the same bytecode will run fine on either a 32 or 64 bit computer. This gets rid of the problem of having to include (encrypted) source code in an iOS IPA file (like other systems do - that also have had their encryption cracked).

    Likes: Atavismus, antix

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+2 / -0 )Share on Facebook
  • I think it would be a good idea to document these "Lua extensions" separately, maybe under a new tab, to avoid confusion?
    My Gideros games: www.totebo.com
    +1 -1 (+6 / -0 )Share on Facebook
  • jdbcjdbc Member
    edited November 2017
    Better and easier syntax for Lua arrays.
  • @jdbc - that's good as the title of one of the 'extensions'.

    I don't know what the name of the mutation operators should be.

    @totebo How do you add an extra tab - I have no idea.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • Also no idea! Meant next to "Main API", "Physics API", "Lua API" etc.
    My Gideros games: www.totebo.com
  • also "Labs" could/should be merged with "Plugins", doesn't it?

    Likes: antix

    +1 -1 (+1 / -0 )Share on Facebook
  • I've written the docs for the enhancements. Hopefully @hgy29 can add them in the next build.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • EricCarrEricCarr Member
    edited November 2017
    This is exciting! I love using += in other languages. It's finally coming to Gideros Lua. :D
    +1 -1 (+2 / -0 )Share on Facebook
  • With (a lot of) @hgy29 's help I've added some help text about the Lua enhancements...

    http://docs.giderosmobile.com/reference/enhancement

    Likes: totebo

    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
    +1 -1 (+1 / -0 )Share on Facebook
  • Awesome! Neat and tidy.

    Likes: SinisterSoft

    My Gideros games: www.totebo.com
    +1 -1 (+1 / -0 )Share on Facebook
  • New proper forum announcement post :)
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • piepie Member
    edited November 2017
    @SinisterSoft Univeral Bytecode :)

    p.s. great job, thanks!

    Likes: SinisterSoft

    +1 -1 (+1 / -0 )Share on Facebook
  • Well spotted. fixed for next update by @hgy29.
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
Sign In or Register to comment.