lua 5.2 - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 11-25-2016, 06:22 AM   #1
FlightControl
Senior Member
 
FlightControl's Avatar
 
Join Date: Mar 2012
Location: Antwerp, Belgium
Posts: 2,014
Exclamation lua 5.2

Dear ED,

Suggest that together with the move to 2.5, DCS world also upgrade the lua version from 5.1 to 5.2.4.

One of the main reasons the move would make sense is that 5.2.4 implements table finalizers (destructors). In lua 5.1 I need to help myself with the ugly newproxy undocumented function to build finalizers. The other advantage would be to be able to set ephemeron weak tables.

Also note that there are issues with building multiple threads in DCS. For some reason a yielded function crashes when it is resumed through an event trigger. With crashing I mean really crashing... Hehehe... DCS stops working. Highly likely there is either a problem with the local stack of the thread, or the thread got garbage collected... Don't know...

Anyway, I have workarounds for both the finalizers and the yield problem.
But it would he really nice to upgrade to lua 5.2.4.

This is what lua 5.2.4 provides additionally:
Lua 5.2 was released on 16 Dec 2011. Its main new features are yieldable pcall and metamethods, new lexical scheme for globals, ephemeron tables, new library for bitwise operations, light C functions, emergency garbage collector, goto statement, and finalizers for tables.

The last release is Lua 5.2.4, released on 07 Mar 2015.

Fc
__________________
FlightControl is offline   Reply With Quote
Old 11-26-2016, 03:34 AM   #2
FlightControl
Senior Member
 
FlightControl's Avatar
 
Join Date: Mar 2012
Location: Antwerp, Belgium
Posts: 2,014
Default

Nobody?
__________________
FlightControl is offline   Reply With Quote
Old 11-26-2016, 05:54 AM   #3
Drexx
Member
 
Join Date: Jul 2016
Posts: 319
Default

I was trying to bring this up to the people I met, one of the questions was:

'is it fully backwards compatible?"
Drexx is offline   Reply With Quote
Old 11-26-2016, 08:44 AM   #4
FlightControl
Senior Member
 
FlightControl's Avatar
 
Join Date: Mar 2012
Location: Antwerp, Belgium
Posts: 2,014
Default

Quote:
Originally Posted by Drexx View Post
I was trying to bring this up to the people I met, one of the questions was:

'is it fully backwards compatible?"
Hi Drexx,

Thanks for your feedback.
Who did you meet and why is meeting people relevant in this discussion?
__________________
FlightControl is offline   Reply With Quote
Old 11-26-2016, 08:53 AM   #5
Bushmanni
Senior Member
 
Join Date: Dec 2009
Location: Finland, Kuopio
Posts: 1,288
Default

He means that he's been asking what other people would think about it and their concern is if it's backwards compatible. The current version gets the job done for the most people so the question is if the improvements you describe are worth the possible issue with backwards compatibility. First of all, is there issue with backwards compatibility and if there is then what can you do with the newer version that justifies the compatibility issue? Better multithreading is meaningless unless you have some use for it that benefits the majority at least in a form of simple to use script that mission builders can use to build great missions.
__________________
DCS Finland: Suomalainen DCS yhteisö -- Finnish DCS community
--------------------------------------------------
SF Squadron

Last edited by Bushmanni; 11-26-2016 at 08:58 AM.
Bushmanni is offline   Reply With Quote
Old 12-05-2016, 11:37 AM   #6
FlightControl
Senior Member
 
FlightControl's Avatar
 
Join Date: Mar 2012
Location: Antwerp, Belgium
Posts: 2,014
Post

Quote:
Originally Posted by Bushmanni View Post
He means that he's been asking what other people would think about it and their concern is if it's backwards compatible. The current version gets the job done for the most people so the question is if the improvements you describe are worth the possible issue with backwards compatibility. First of all, is there issue with backwards compatibility and if there is then what can you do with the newer version that justifies the compatibility issue? Better multithreading is meaningless unless you have some use for it that benefits the majority at least in a form of simple to use script that mission builders can use to build great missions.
Hi Bushmanni,

Thanks for your feedback, your comments make a lot of sense.
There aren't that many people in the DCS world who would be interested in this upgrade, indeed ... Only a few, and myself included... There is no compelling reason why this upgrade should happen, as I wrote in the mail before.

But, if such upgrade would be doable, and backward compatibility would be guaranteed, it would be able for a bit more elegant lua in a couple of areas.

The first is how finalizers would be coded ... A finalizer is a piece of code, that gets executed when a table gets garbage collected. It is almost like a destructor, only that a destructor gets immediately executed, while a finalizer gets only executed when garbage collected...

Let me give an example why a finalizer is useful ... If I set a menu within lua, using MOOSE for an alive group, I can do this as follows:

Code:
local Plane = GROUP:FindByName( "Airplane" ) -- Find the group of a Client ...
Menu = GROUP_MENU_COMMAND( Plane, "Report", nil, ReportFunction, {} )
I would like to have the behaviour that, when the Plane gets destroyed, that then also the Menu is removed automatically...

Within lua, i am able to simulate this by adding the following code:

Code:
function Plane:_Destructor()
  Menu:Remove()
end
So, when I execute the following command:
Code:
Plane = nil
collectgarbage()
then the _Destructor method is executed ...

Within lua 5.1, this behaviour is implemented in a "ugly" way, by using the newproxy method. See the method here:

Code:
function BASE:_Destructor()
  --self:E("_Destructor")

  self:EventRemoveAll()
end

function BASE:_SetDestructor()

  local proxy = newproxy(true)
  local proxyMeta = getmetatable(proxy)

  proxyMeta.__gc = function ()
    env.info("In __gc for " .. self:GetClassNameAndID() )
    if self._Destructor then
        self:_Destructor()
    end
  end

  -- keep the userdata from newproxy reachable until the object
  -- table is about to be garbage-collected - then the __gc hook
  -- will be invoked and the destructor called
  rawset( self, '__proxy', proxy )

end
This is what i have currently in the MOOSE framework written, to implement a finalizer...

The code could look more elegant like this in lua 5.2:

Code:
function BASE:_SetDestructor()
  self.__gc = _Destructor
end
So, is not having lua 5.2 a showstopper, hardly ...

The second reason to have lua 5.2, is to be able to work with ephemeron tables...

Code:
setmetatable(mem, {__mode = "k"})
This construct is not possible in lua 5.1. The value is strong, but the key is weak. This function would be really helpful in the event dispatcher in MOOSE. It holds references to all kinds of classes that catch events... Once the key to the object is nilled, these objects should also be removed from the event catching table ... In other words, this problem solves the publish-subscribe reference problem. But i am able to solve this in lua 5.1, but need to code extra for it...

About the multi threaded, i think you've misunderstood my writing ... lua is not pre-emptive multi threaded. But i just wonder whether in lua 5.2, the yield() would work when a scheduled event re-schedules ...

In lua 5.1 i get a crash. But again, am able to work around this ...

FC
__________________
FlightControl is offline   Reply With Quote
Old 03-15-2017, 03:10 AM   #7
FlightControl
Senior Member
 
FlightControl's Avatar
 
Join Date: Mar 2012
Location: Antwerp, Belgium
Posts: 2,014
Default

anybody?
__________________
FlightControl is offline   Reply With Quote
Old 06-19-2018, 08:05 PM   #8
VladMordock
Junior Member
 
VladMordock's Avatar
 
Join Date: Jan 2018
Location: Kraków, PL
Posts: 25
Default

What's the actual lua version in DCS 2.5 Beta?
__________________
Zapraszam na Gildia.org - polska społeczność DCS.
VladMordock is offline   Reply With Quote
Reply

Tags
lua

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:30 AM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.