Quote from: reyalp on 07 / April / 2013, 19:21:58QuoteKnown bug: the function "restore" in fps.lua doesn't get called when the script is interrupted (according to http://chdk.wikia.com/wiki/Script_commands#restore it should, not sure what's wrong)restore needs to be defined before the script is interrupted, above the while loop.While I have no doubt that you are correct about this, it seems strange. As I understand it, Lua compiles to an intermediate state (like the old p-code) before executing (hence the error message that pop up when you try to run a script with syntax mistakes). Seems like it should be able to spot a restore() function and do something appropriate at that point?
QuoteKnown bug: the function "restore" in fps.lua doesn't get called when the script is interrupted (according to http://chdk.wikia.com/wiki/Script_commands#restore it should, not sure what's wrong)restore needs to be defined before the script is interrupted, above the while loop.
Known bug: the function "restore" in fps.lua doesn't get called when the script is interrupted (according to http://chdk.wikia.com/wiki/Script_commands#restore it should, not sure what's wrong)
Seems like it should be able to spot a restore() function and do something appropriate at that point?
function foo() ... end
foo = function() ... end
while ... do...endfunction restore()end
function shutdown_callback()....endregister_restore_routine( shutdown_callback )
However, I do find it strange that given all that, Lua would arbitrarily designate a specific function name for the code that gets called when the program halts.
// run the "restore" function at the end of a script// Mimic uBasic logic, return 0 to trigger script interrupt immediatelyint lua_run_restore(){ lua_getglobal(Lt, "restore"); if (lua_isfunction(Lt, -1)) { if (lua_pcall( Lt, 0, 0, 0 )) { script_console_add_line( (long)lua_tostring( Lt, -1 ) ); } if (lua_script_is_ptp == 0) script_console_add_line(LANG_CONSOLE_TEXT_FINISHED); } return 0;}
So I think that tells me that the whole restore() thing is a CHDK implementation detail and nothing to do with core Lua. Do I have that right ?
While we're at it, I'd like to understand the use of "local" variables a little better. I understand that their scope is within the block they're contained in. But shouldn't we be using local variables whenever possible?And what's the meaning of a local variable defined at the beginning of the "main" block? Is that permitted?
function foo()return x+1endlocal x = 1foo()
I read that local variables are accessed with an index address, while global variables use a hash table? Can you explain this? Would this mean that local variables take less memory and are accessed faster? Is the text name of a global variable stored, so longer names take more memory?
I was thinking about writing a program in Lua to run on the computer, not the camera. How hard is it to create a complete file that runs a Lua program on Windows or Mac, i.e. would the Lua program be cross platform?
So would a local variable defined in the main chunk be visible to all the functions defined in the main chunk?
How about in libraries loaded by the main chunk?
bob=require'capmode'bob.set'M'
require'capmode'.set'M'
Something tells me Lua is not going to end up in SDM any time soon.
Started by flarn2006 Feature Requests
Started by waterwingz General Discussion and Assistance
Started by philmoz « 1 2 3 4 » General Discussion and Assistance
Started by waffenschmidt Hotwire! Hardware Mods, Accessories and Insights
Started by reyalp General Discussion and Assistance