Jump to content
  • 0

Deleting the application cache via lua script


Unclear

Question

Posted

Good evening!
[I am writing to you from a translator.]

I created a topic in order to understand how you can write a function so that when the script ends correctly, the application cache is deleted. And also if the application was terminated abruptly before the script completed properly.

If anyone has ideas or examples, I will be glad to learn new things.
Now I'm looking at online play. I want to implement functions that have no analogues on the open spaces of the available Internet.

Sorry if I couldn't make my thoughts clear.

3 answers to this question

Recommended Posts

Posted

Hi @Unclear, I would say that it is requires more works than you think. To do this you need to use Threading or Multiprocessing to watch your Process. This however needs to be implemented outside LUA, you can use C or Python as wrapper to LUA. For example if the Bundled LUA Script abruptly exit, it can still properly remove the resources you want. Assuming that you're developing an Application. So it cannot be directly removed, you can however try some explicit approach:

  • - Try Except: Script abruption will raises Exception. However, this is intended for chunks of code not your entire script. Try-Catch-Finally.lua
  • - Proxy: If you're using iteration of LUA that unders <5.1, you can use Proxy to handle the LUA garbage collection: AtExit
  • - Metatable: Newer iteration >5.2, you can can call function through setmetatable:
setmetatable({}, {__gc = function()
	print('do something')
	end
})

Even LUA as Programming Language, it's main intention is for Extension. As far as I know, LUA cannot do condition if exitted. Once it's exit, it's exit. For such related questions, you can ask them at: Stack Overflow

Update:
I have fixed the code, so you can do something directly at one liner @Unclear

Posted

[I am writing to you from a translator.]

Thank you. I will try to implement through Python.
It's a pity that LUA does not support the ability to delete data from media.

The last question I think. Is it possible to run a Python script through LUA?

Posted
19 hours ago, Unclear said:

[I am writing to you from a translator.]

Thank you. I will try to implement through Python.
It's a pity that LUA does not support the ability to delete data from media.

The last question I think. Is it possible to run a Python script through LUA?

yes it's possible but GG accept only lua , embedding lua in py you may need termux to do that.
The coroutine library is missing. Some functions are blocked for security reasons (os.execute, io.popen)

21 hours ago, MC189 said:
setmetatable({}, {__gc = function()
	print('do something')
	end
})

 

__gc metamethods do not work.

Data in local variables may not be collected by garbage collection, even if the variables are out of scope. Use the assignment to nil to allow garbage collection to remove the object.

Deletion of dependent objects does not occur in one garbage collection, as in the original Lua. For a dependency of depth N, N steps of garbage collection are required.

collectgarbage is not a direct order to collect garbage. This is just a hint for the garbage collector. Garbage collection may not be completed.

source

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.