CHDK_DE Vorschauversion  Trunk Rev. 5273
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
luascript.c-Dateireferenz
#include "camera_info.h"
#include "stdlib.h"
#include "gui.h"
#include "gui_draw.h"
#include "script.h"
#include "script_key_funcs.h"
#include "conf.h"
#include "shot_histogram.h"
#include "raw.h"
#include "levent.h"
#include "console.h"
#include "action_stack.h"
#include "ptp_chdk.h"
#include "lang.h"
#include "gui_lang.h"
#include "histogram.h"
#include "shooting.h"
#include "autoiso.h"
#include "remotecap.h"
#include "battery.h"
#include "temperature.h"
#include "backlight.h"
#include "keyboard.h"
#include "shutdown.h"
#include "sound.h"
#include "modes.h"
#include "sd_card.h"
#include "clock.h"
#include "lens.h"
#include "properties.h"
#include "file_counter.h"
#include "debug_led.h"
#include "meminfo.h"
#include "callfunc.h"
#include "usb_remote.h"
#include "script_api.h"
#include "curves.h"
#include "motion_detector.h"
#include "raw_merge.h"
#include "gui_fselect.h"
#include "gui_tbox.h"
#include "module_def.h"
#include "luascript.h"
#include "script_shoot_hook.h"
#include "rawhookops.h"
#include "../lib/lua/lualib.h"
#include "../lib/lua/lauxlib.h"
#include "../lib/lua/lstate.h"
+ Include-Abhängigkeitsdiagramm für luascript.c:

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define YIELD_CHECK_COUNT   100
 
#define YIELD_MAX_COUNT_DEFAULT   25
 
#define YIELD_MAX_MS_DEFAULT   10
 
#define FUNC(X)   { #X, luaCB_##X },
 

Funktionen

void register_lua_funcs (lua_State *L)
 
static void lua_script_disable_yield_hook (void)
 
static void lua_script_enable_yield_hook (void)
 
static ptp_script_msglua_create_usb_msg (lua_State *L, int index, unsigned msgtype)
 
void lua_script_reset ()
 
void lua_script_error_ptp (int runtime, const char *err)
 
static void lua_count_hook (lua_State *L, lua_Debug *ar)
 
int lua_script_error (lua_State *Lt, int runtime)
 
void lua_script_finish (lua_State *L)
 
int lua_script_start (char const *script, int ptp)
 
int lua_script_start_file (char const *filename)
 
int lua_script_run (void)
 
int lua_run_restore ()
 
static int lua_get_key_arg (lua_State *L, int narg)
 
static unsigned on_off_value_from_lua_arg (lua_State *L, int index)
 
static int luaCB_set_curve_state (lua_State *L)
 
static int luaCB_get_curve_state (lua_State *L)
 
static int luaCB_set_curve_file (lua_State *L)
 
static int luaCB_get_curve_file (lua_State *L)
 
static int luaCB_set_aelock (lua_State *L)
 
static int luaCB_set_aflock (lua_State *L)
 
static int luaCB_set_mf (lua_State *L)
 
static int luaCB_get_sd_over_modes (lua_State *L)
 
static int luaCB_shoot (lua_State *L)
 
static int action_stack_AS_LUA_SLEEP ()
 
static int sleep_delay (int delay)
 
static int luaCB_sleep (lua_State *L)
 
static int luaCB_keyfunc (lua_State *L)
 
static int luaCB_cls (lua_State *L)
 
static int luaCB_set_console_layout (lua_State *L)
 
static int luaCB_set_console_autoredraw (lua_State *L)
 
static int luaCB_console_redraw (lua_State *L)
 
static int luaCB_get_partitionInfo (lua_State *L)
 
static int luaCB_swap_partitions (lua_State *L)
 
static int luaCB_get_av96 (lua_State *L)
 
static int luaCB_get_bv96 (lua_State *L)
 
static int luaCB_get_day_seconds (lua_State *L)
 
static int luaCB_get_disk_size (lua_State *L)
 
static int luaCB_get_dofinfo (lua_State *L)
 
static int luaCB_get_free_disk_space (lua_State *L)
 
static int luaCB_get_focus (lua_State *L)
 
static int luaCB_get_iso_market (lua_State *L)
 
static int luaCB_get_iso_mode (lua_State *L)
 
static int luaCB_get_iso_real (lua_State *L)
 
static int luaCB_get_jpg_count (lua_State *L)
 
static int luaCB_get_prop (lua_State *L)
 
static int luaCB_get_prop_str (lua_State *L)
 
static int luaCB_get_raw_support (lua_State *L)
 
static int luaCB_get_raw_count (lua_State *L)
 
static int luaCB_get_sv96 (lua_State *L)
 
static int luaCB_get_tick_count (lua_State *L)
 
static int luaCB_get_exp_count (lua_State *L)
 
static int luaCB_get_image_dir (lua_State *L)
 
static int luaCB_get_tv96 (lua_State *L)
 
static int luaCB_get_user_av_id (lua_State *L)
 
static int luaCB_get_user_av96 (lua_State *L)
 
static int luaCB_get_min_av96 (lua_State *L)
 
static int luaCB_get_max_av96 (lua_State *L)
 
static int luaCB_get_current_av96 (lua_State *L)
 
static int luaCB_get_current_tv96 (lua_State *L)
 
static int luaCB_get_nd_value_ev96 (lua_State *L)
 
static int luaCB_get_nd_current_ev96 (lua_State *L)
 
static int luaCB_get_imager_active (lua_State *L)
 
static int luaCB_get_user_tv_id (lua_State *L)
 
static int luaCB_get_user_tv96 (lua_State *L)
 
static int luaCB_get_vbatt (lua_State *L)
 
static int luaCB_get_zoom (lua_State *L)
 
static int luaCB_get_parameter_data (lua_State *L)
 
static int luaCB_get_flash_params_count (lua_State *L)
 
static int luaCB_set_av96_direct (lua_State *L)
 
static int luaCB_set_av96 (lua_State *L)
 
static int luaCB_set_focus_interlock_bypass (lua_State *L)
 
static int luaCB_set_focus (lua_State *L)
 
static int luaCB_set_iso_mode (lua_State *L)
 
static int luaCB_set_iso_real (lua_State *L)
 
static int luaCB_set_led (lua_State *L)
 
static int luaCB_set_nd_filter (lua_State *L)
 
static int luaCB_set_prop (lua_State *L)
 
static int luaCB_set_prop_str (lua_State *L)
 
static int luaCB_set_raw_nr (lua_State *L)
 
static int luaCB_get_raw_nr (lua_State *L)
 
static int luaCB_set_raw (lua_State *L)
 
static int luaCB_get_raw (lua_State *L)
 
static int luaCB_set_sv96 (lua_State *L)
 
static int luaCB_set_tv96_direct (lua_State *L)
 
static int luaCB_set_tv96 (lua_State *L)
 
static int luaCB_set_user_av_by_id_rel (lua_State *L)
 
static int luaCB_set_user_av_by_id (lua_State *L)
 
static int luaCB_set_user_av96 (lua_State *L)
 
static int luaCB_set_user_tv_by_id_rel (lua_State *L)
 
static int luaCB_set_user_tv_by_id (lua_State *L)
 
static int luaCB_set_user_tv96 (lua_State *L)
 
static int luaCB_set_zoom_speed (lua_State *L)
 
static int luaCB_set_zoom_rel (lua_State *L)
 
static int luaCB_set_zoom (lua_State *L)
 
static int action_stack_AS_LUA_WAIT_CLICK ()
 
static int luaCB_wait_click (lua_State *L)
 
static int luaCB_is_pressed (lua_State *L)
 
static int luaCB_is_key (lua_State *L)
 
static int luaCB_set_exit_key (lua_State *L)
 
static int luaCB_wheel_right (lua_State *L)
 
static int luaCB_wheel_left (lua_State *L)
 
static int luaCB_md_af_led_control (lua_State *L)
 
static int luaCB_md_get_cell_diff (lua_State *L)
 
static int luaCB_md_get_cell_val (lua_State *L)
 
static int luaCB_md_detect_motion (lua_State *L)
 
static void return_string_selected (const char *str)
 
static int action_stack_AS_WAIT_MODULE ()
 
static int luaCB_file_browser (lua_State *L)
 
static int luaCB_textbox (lua_State *L)
 
static int luaCB_draw_pixel (lua_State *L)
 
static int luaCB_draw_line (lua_State *L)
 
static int luaCB_draw_rect (lua_State *L)
 
static int luaCB_draw_rect_filled (lua_State *L)
 
static int luaCB_draw_ellipse (lua_State *L)
 
static int luaCB_draw_ellipse_filled (lua_State *L)
 
static int luaCB_draw_string (lua_State *L)
 
static int luaCB_draw_clear (lua_State *L)
 
static int luaCB_get_gui_screen_width (lua_State *L)
 
static int luaCB_get_gui_screen_height (lua_State *L)
 
static int luaCB_autostarted (lua_State *L)
 
static int luaCB_get_autostart (lua_State *L)
 
static int luaCB_set_autostart (lua_State *L)
 
static int luaCB_get_usb_power (lua_State *L)
 
static int luaCB_set_remote_timing (lua_State *L)
 
static int luaCB_usb_force_active (lua_State *L)
 
static int luaCB_usb_sync_wait (lua_State *L)
 
static int luaCB_enter_alt (lua_State *L)
 
static int luaCB_exit_alt (lua_State *L)
 
static int luaCB_get_alt_mode (lua_State *L)
 
static int luaCB_shut_down (lua_State *L)
 
static int luaCB_print_screen (lua_State *L)
 
static int luaCB_get_movie_status (lua_State *L)
 
static int luaCB_set_movie_status (lua_State *L)
 
static int luaCB_get_video_button (lua_State *L)
 
static int luaCB_get_video_recording (lua_State *L)
 
static int luaCB_get_drive_mode (lua_State *L)
 
static int luaCB_get_focus_mode (lua_State *L)
 
static int luaCB_get_focus_state (lua_State *L)
 
static int luaCB_get_focus_ok (lua_State *L)
 
static int luaCB_get_flash_mode (lua_State *L)
 
static int luaCB_get_shooting (lua_State *L)
 
static int luaCB_get_flash_ready (lua_State *L)
 
static int luaCB_get_IS_mode (lua_State *L)
 
static int luaCB_get_orientation_sensor (lua_State *L)
 
static int luaCB_get_zoom_steps (lua_State *L)
 
static int luaCB_get_nd_present (lua_State *L)
 
static int luaCB_get_propset (lua_State *L)
 
static int luaCB_get_ev (lua_State *L)
 
static int luaCB_set_ev (lua_State *L)
 
static int luaCB_get_histo_range (lua_State *L)
 
static int luaCB_shot_histo_enable (lua_State *L)
 
static int luaCB_shot_histo_write_to_file (lua_State *L)
 
static int luaCB_get_live_histo (lua_State *L)
 
static int luaCB_play_sound (lua_State *L)
 
static int luaCB_get_temperature (lua_State *L)
 
static int luaCB_get_time (lua_State *L)
 
static int luaCB_peek (lua_State *L)
 
static int luaCB_poke (lua_State *L)
 
static int luaCB_bitand (lua_State *L)
 
static int luaCB_bitor (lua_State *L)
 
static int luaCB_bitxor (lua_State *L)
 
static int luaCB_bitshl (lua_State *L)
 
static int luaCB_bitshri (lua_State *L)
 
static int luaCB_bitshru (lua_State *L)
 
static int luaCB_bitnot (lua_State *L)
 
void set_string_field (lua_State *L, const char *key, const char *val)
 
void set_number_field (lua_State *L, const char *key, int val)
 
static int luaCB_get_buildinfo (lua_State *L)
 
static int luaCB_get_mode (lua_State *L)
 
static int luaCB_set_raw_develop (lua_State *L)
 
static int luaCB_raw_merge_start (lua_State *L)
 
static int luaCB_raw_merge_add_file (lua_State *L)
 
static int luaCB_raw_merge_end (lua_State *L)
 
static int luaCB_set_backlight (lua_State *L)
 
static int luaCB_set_lcd_display (lua_State *L)
 
static int luaCB_set_draw_title_line (lua_State *L)
 
static int luaCB_get_draw_title_line (lua_State *L)
 
static unsigned levent_id_from_lua_arg (lua_State *L, int index)
 
static unsigned levent_index_from_id_lua_arg (lua_State *L, int index)
 
static int luaCB_get_levent_def (lua_State *L)
 
static int luaCB_get_levent_index (lua_State *L)
 
static int luaCB_get_levent_def_by_index (lua_State *L)
 
static int luaCB_post_levent_to_ui (lua_State *L)
 
static int luaCB_post_levent_for_npt (lua_State *L)
 
static int luaCB_set_levent_active (lua_State *L)
 
static int luaCB_set_levent_script_mode (lua_State *L)
 
static int luaCB_set_capture_mode_canon (lua_State *L)
 
static int luaCB_set_capture_mode (lua_State *L)
 
static int luaCB_is_capture_mode_valid (lua_State *L)
 
static int luaCB_set_record (lua_State *L)
 
static int luaCB_switch_mode_usb (lua_State *L)
 
static int pack_native_args (lua_State *L, unsigned start, unsigned *argbuf)
 
static int luaCB_call_func_ptr (lua_State *L)
 
unsigned _ExecuteEventProcedure (const char *name,...)
 
static int luaCB_call_event_proc (lua_State *L)
 
static int luaCB_reboot (lua_State *L)
 
static int luaCB_get_config_value (lua_State *L)
 
static int luaCB_set_config_value (lua_State *L)
 
static int luaCB_set_config_autosave (lua_State *L)
 
static int luaCB_save_config_file (lua_State *L)
 
static int luaCB_load_config_file (lua_State *L)
 
static int luaCB_set_file_attributes (lua_State *L)
 
static int action_stack_AS_SCRIPT_READ_USB_MSG ()
 
static int action_stack_AS_SCRIPT_WRITE_USB_MSG ()
 
static int luaCB_read_usb_msg (lua_State *L)
 
static int luaCB_write_usb_msg (lua_State *L)
 
static void set_meminfo_num (lua_State *L, const char *name, int val)
 
static int luaCB_get_meminfo (lua_State *L)
 
static int luaCB_set_yield (lua_State *L)
 
static int luaCB_get_usb_capture_support (lua_State *L)
 
static int luaCB_init_usb_capture (lua_State *L)
 
static int luaCB_get_usb_capture_target (lua_State *L)
 
static int luaCB_set_usb_capture_timeout (lua_State *L)
 
static int luaCB_iso_to_sv96 (lua_State *L)
 
static int luaCB_sv96_to_iso (lua_State *L)
 
static int luaCB_iso_real_to_market (lua_State *L)
 
static int luaCB_iso_market_to_real (lua_State *L)
 
static int luaCB_sv96_real_to_market (lua_State *L)
 
static int luaCB_sv96_market_to_real (lua_State *L)
 
static int luaCB_aperture_to_av96 (lua_State *L)
 
static int luaCB_av96_to_aperture (lua_State *L)
 
static int luaCB_usec_to_tv96 (lua_State *L)
 
static int luaCB_tv96_to_usec (lua_State *L)
 
static int luaCB_seconds_to_tv96 (lua_State *L)
 
static int luaCB_shoot_hook_set (lua_State *L)
 
static int luaCB_shoot_hook_is_ready (lua_State *L)
 
static int luaCB_shoot_hook_continue (lua_State *L)
 
static int luaCB_shoot_hook_count (lua_State *L)
 
void register_shoot_hook_fn (lua_State *L, int hook, void *hook_fn, const char *name)
 
void register_shoot_hooks (lua_State *L)
 
static void lua_set_variable (char *name, int value, int isBool, int isTable, int labelCount, const char **labels)
 
static void lua_set_as_ret (int md_ret)
 

Variablen

lua_StateL
 
lua_StateLt
 
static int lua_script_is_ptp
 
static int ptp_saved_alt_state
 
static int run_first_resume
 
static int run_start_tick
 
static int run_hook_count
 
static unsigned yield_max_count
 
static unsigned yield_max_ms
 
static int yield_hook_enabled
 
static const luaL_Reg chdk_funcs []
 
libscriptapi_sym _liblua
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define FUNC (   X)    { #X, luaCB_##X },

Definiert in Zeile 2730 der Datei luascript.c.

#define YIELD_CHECK_COUNT   100

Definiert in Zeile 86 der Datei luascript.c.

#define YIELD_MAX_COUNT_DEFAULT   25

Definiert in Zeile 87 der Datei luascript.c.

#define YIELD_MAX_MS_DEFAULT   10

Definiert in Zeile 88 der Datei luascript.c.

Dokumentation der Funktionen

unsigned _ExecuteEventProcedure ( const char *  name,
  ... 
)
static int action_stack_AS_LUA_SLEEP ( )
static

Definiert in Zeile 446 der Datei luascript.c.

447 {
448  if (get_tick_count() >= action_top(2))
449  {
450  action_pop_func(1);
451  return 1;
452  }
453  return 0;
454 }
static int action_stack_AS_LUA_WAIT_CLICK ( )
static

Definiert in Zeile 1055 der Datei luascript.c.

1056 {
1057  // Check key pressed or timeout
1059  {
1060  // If timed out set key state to "no_key", otherwise key pressed so set last checked time
1063  else
1065 
1066  action_pop_func(1);
1067  return 1;
1068  }
1069 
1070  return 0;
1071 }
static int action_stack_AS_SCRIPT_READ_USB_MSG ( )
static

Definiert in Zeile 2348 der Datei luascript.c.

2349 {
2351 
2352  if ((get_tick_count() >= action_top(2)) || msg)
2353  {
2354  if (msg && msg->data)
2355  {
2356  lua_pushlstring(Lt,msg->data,msg->size);
2357  }
2358  else
2359  {
2360  lua_pushnil(Lt);
2361  }
2362  action_pop_func(1);
2363  return 1;
2364  }
2365  return 0;
2366 }
static int action_stack_AS_SCRIPT_WRITE_USB_MSG ( )
static

Definiert in Zeile 2368 der Datei luascript.c.

2369 {
2371 
2372  int r = ptp_script_write_msg(msg);
2373 
2374  if ((get_tick_count() >= action_top(3)) || r)
2375  {
2376  lua_pushboolean(Lt,r);
2377  action_pop_func(2);
2378  return 1;
2379  }
2380  return 0;
2381 }
static int action_stack_AS_WAIT_MODULE ( )
static

Definiert in Zeile 1200 der Datei luascript.c.

1201 {
1202  // state_kbd_script_run is set to 0 when the file browser is started from a Lua script
1203  // it is reset back to 1 when the file browser exits and control is returned back to
1204  // the script
1206  {
1207  action_pop_func(0);
1208  }
1209  return 0;
1210 }
static unsigned levent_id_from_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 1880 der Datei luascript.c.

1881 {
1882  unsigned event_id;
1883  if (lua_type(L, index) == LUA_TSTRING) {
1884  const char *ev_name = lua_tostring(L, index);
1885  event_id = levent_id_for_name(ev_name);
1886  if (event_id == 0) {
1887  return luaL_error( L, "bad event name '%s'", ev_name );
1888  }
1889  }
1890  // could check here if it is in the table, but even valid ones can crash
1891  // so we avoid searching the table if given a number
1892  else if (lua_type(L,index) == LUA_TNUMBER){
1893  event_id = lua_tonumber(L,index);
1894  }
1895  else {
1896  return luaL_error( L, "expected event name or id" );
1897  }
1898  return event_id;
1899 }
static unsigned levent_index_from_id_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 1905 der Datei luascript.c.

1906 {
1907  if (lua_type(L, index) == LUA_TSTRING) {
1908  return levent_index_for_name(lua_tostring(L, index));
1909  }
1910  else if (lua_type(L,index) == LUA_TNUMBER){
1911  return levent_index_for_id(lua_tonumber(L,index));
1912  }
1913  else {
1914  return luaL_error( L, "expected string or number" );
1915  }
1916 }
static void lua_count_hook ( lua_State L,
lua_Debug ar 
)
static

Definiert in Zeile 184 der Datei luascript.c.

185 {
186  run_hook_count++;
187  if( L->nCcalls > L->baseCcalls || !yield_hook_enabled )
188  return;
190  lua_yield( L, 0 );
191 }
static ptp_script_msg* lua_create_usb_msg ( lua_State L,
int  index,
unsigned  msgtype 
)
static

Definiert in Zeile 102 der Datei luascript.c.

102  {
103  // TODO maybe we should just pass the lua type constants
104  unsigned datatype, datasize = 4;
105  int ivalue = 0;
106  void *data = &ivalue;
107  int ltype = lua_type(L,index);
108  switch(ltype) {
109  case LUA_TNONE:
110  return NULL; // nothing on the stack, no message generated
111  break;
112  case LUA_TNIL:
113  datatype = PTP_CHDK_TYPE_NIL;
114  break;
115  case LUA_TBOOLEAN:
116  datatype = PTP_CHDK_TYPE_BOOLEAN;
117  ivalue = lua_toboolean(L,index);
118  break;
119  case LUA_TNUMBER:
120  datatype = PTP_CHDK_TYPE_INTEGER;
121  ivalue = lua_tonumber(L,index);
122  break;
123  case LUA_TSTRING:
124  datatype = PTP_CHDK_TYPE_STRING;
125  data = (char *)lua_tolstring(L,index,&datasize);
126  break;
127  // TODO this uses usb_msg_table_to_string to serialize the table
128  // the default format is described in
129  // http://chdk.setepontos.com/index.php?topic=4338.msg62606#msg62606
130  // other formats can be implemented by overriding this function in your lua code
131  case LUA_TTABLE: {
132  int result;
133  lua_script_disable_yield_hook(); // don't want to yield while converting
134  lua_getglobal(L, "usb_msg_table_to_string"); // push function
135  lua_pushvalue(L, index); // copy specified index to top of stack
136  result = lua_pcall(L,1,1,0); // this will leave an error message as a string on the stack if call fails
138  if( result ) {
139  // if called from lua, throw a normal error
140  if( msgtype == PTP_CHDK_S_MSGTYPE_USER ) {
141  luaL_error(L,lua_tostring(L,-1));
142  return NULL; // not reached
143  } else { // if it's a return, convert the message to an ERR
144  msgtype = PTP_CHDK_S_MSGTYPE_ERR;
145  datatype = PTP_CHDK_S_ERRTYPE_RUN;
146  data = (char *)lua_tolstring(L,-1,&datasize);
147  break;
148  }
149  }
150  // an empty table is returned as an empty string by default
151  // a non-string should never show up here
152  if ( !lua_isstring(L,-1) ) {
153  return NULL;
154  }
155  datatype = PTP_CHDK_TYPE_TABLE;
156  data = (char *)lua_tolstring(L,-1,&datasize);
157  lua_pop(L,1);
158  }
159  break;
160  default:
161  datatype = PTP_CHDK_TYPE_UNSUPPORTED;
162  data = (char *)lua_typename(L,ltype); // return type name as message data
163  datasize = strlen(data);
164  }
165  return ptp_script_create_msg(msgtype,datatype,datasize,data);
166 }
static int lua_get_key_arg ( lua_State L,
int  narg 
)
static

Definiert in Zeile 358 der Datei luascript.c.

359 {
360  int k = script_keyid_by_name( luaL_checkstring( L, narg ) );
361  if(!k)
362  luaL_error( L, "unknown key" );
363  return k;
364 }
int lua_run_restore ( )

Definiert in Zeile 344 der Datei luascript.c.

345 {
346  lua_getglobal(Lt, "restore");
347  if (lua_isfunction(Lt, -1)) {
348  if (lua_pcall( Lt, 0, 0, 0 )) {
349  script_console_add_line( (long)lua_tostring( Lt, -1 ) );
350  }
351  if (lua_script_is_ptp == 0)
353  }
354  return 0;
355 }
static void lua_script_disable_yield_hook ( void  )
static

Definiert in Zeile 93 der Datei luascript.c.

93  {
95 }
static void lua_script_enable_yield_hook ( void  )
static

Definiert in Zeile 96 der Datei luascript.c.

96  {
98 }
int lua_script_error ( lua_State Lt,
int  runtime 
)

Definiert in Zeile 193 der Datei luascript.c.

194 {
195  const char *err = lua_tostring( Lt, -1 );
196 
197  if(err)
198  {
199  if(!*err)
200  {
201  script_console_add_error( (long)"ERROR: empty error message" );
202  }
203  else
204  {
205  script_console_add_error( (long)err );
206  }
207  }
208  else
209  {
210  script_console_add_error( (long)"ERROR: NULL error message" );
211  }
212 
213  if (lua_script_is_ptp)
214  {
215  lua_script_error_ptp(runtime,err);
216  }
217  else
218  {
219  if (runtime)
220  {
222  script_end();
223  script_start_gui(0);
224  return SCRIPT_RUN_RUNNING;
225  }
226  }
227  else // ensure lua_state is closed for compiletime errors
228  {
230  }
231  }
232 
234  return SCRIPT_RUN_ERROR;
235 }
void lua_script_error_ptp ( int  runtime,
const char *  err 
)

Definiert in Zeile 175 der Datei luascript.c.

175  {
176  if(runtime) {
178  } else {
181  }
182 }
void lua_script_finish ( lua_State L)

Definiert in Zeile 239 der Datei luascript.c.

240 {
241  if(lua_script_is_ptp) {
242  // send all return values as RET messages
243  int i,end = lua_gettop(L);
244  for(i=1;i<=end; i++) {
246  // if the queue is full return values will be silently discarded
247  // incompatible types will be returned as TYPE_UNSUPPORTED to preserve expected number and order of return values
248  if(msg) {
249  ptp_script_write_msg(msg);
250  // create_usb_msg may convert the message to an error
251  if(msg->type != PTP_CHDK_S_MSGTYPE_RET) {
252  break;
253  }
254  } else {
255  ptp_script_write_error_msg(PTP_CHDK_S_ERRTYPE_RUN, "error creating return msg");
256  break;
257  }
258  }
259  if(!ptp_saved_alt_state) {
260  exit_alt();
261  }
262  }
263 }
void lua_script_reset ( )

Definiert in Zeile 168 der Datei luascript.c.

169 {
171  lua_close( L );
172  L = 0;
173 }
int lua_script_run ( void  )

Definiert in Zeile 307 der Datei luascript.c.

308 {
309  int Lres;
310  int top;
311  if (run_first_resume) {
312  run_first_resume = 0;
313  top = 0;
314  } else {
315  top = lua_gettop(Lt);
316  }
318  run_hook_count = 0;
319  Lres = lua_resume( Lt, top );
320 
321  if (Lres == LUA_YIELD)
322  {
323  // yielded
324  }
325  else if (Lres != 0)
326  {
327  return lua_script_error(Lt,1);
328  }
329  else
330  {
331  // finished normally, add ptp result
333  // Display 'Finished message', unless running from PTP
334  if (lua_script_is_ptp == 0)
336  return SCRIPT_RUN_ENDED;
337  }
338 
339  return SCRIPT_RUN_RUNNING;
340 }
int lua_script_start ( char const script,
int  ptp 
)

Definiert in Zeile 265 der Datei luascript.c.

266 {
268  lua_script_is_ptp = ptp;
269  if(ptp) {
271  // put ui in alt state to allow key presses to be sent to script
272  // just setting kbd_blocked leaves UI in a confused state
273  if(!ptp_saved_alt_state) {
274  enter_alt();
275  }
276  }
277  L = lua_open();
278  luaL_openlibs( L );
280 
281  Lt = lua_newthread( L );
282  lua_setfield( L, LUA_REGISTRYINDEX, "Lt" );
283  if( luaL_loadstring( Lt, script ) != 0 )
284  {
285  lua_script_error(Lt,0);
286  return 0;
287  }
290  run_first_resume = 1;
293  return 1;
294 }
int lua_script_start_file ( char const filename)

Definiert in Zeile 296 der Datei luascript.c.

297 {
298  static char loader[256];
299  char *wrapper = "";
300  if ((script_version.major == 1) && (script_version.minor == 3))
301  wrapper = "require'wrap13' ";
302  sprintf(loader, "%slocal s,e=loadfile'%s' collectgarbage() if not s then error(e) end s()", wrapper, filename);
303  return lua_script_start(loader, 0);
304 }
static void lua_set_as_ret ( int  md_ret)
static

Definiert in Zeile 3050 der Datei luascript.c.

3050 { lua_pushnumber(Lt,md_ret); }
static void lua_set_variable ( char *  name,
int  value,
int  isBool,
int  isTable,
int  labelCount,
const char **  labels 
)
static

Definiert in Zeile 3025 der Datei luascript.c.

3026 {
3027  lua_pushstring( L, name );
3028  if (isTable)
3029  {
3030  lua_createtable(L, labelCount, 2);
3031  int i;
3032  for (i=0; i<labelCount; i++)
3033  {
3034  lua_pushstring(L,labels[i]);
3035  lua_rawseti(L,-2,i+1);
3036  }
3037  SET_INT_FIELD("index", value+1); // Make value 1 based for Lua table index
3038  SET_STR_FIELD("value", labels[value]);
3039  }
3040  else
3041  {
3042  if (isBool)
3043  lua_pushboolean( L, value );
3044  else
3045  lua_pushnumber( L, value );
3046  }
3048 }
static int luaCB_aperture_to_av96 ( lua_State L)
static

Definiert in Zeile 2649 der Datei luascript.c.

2650 {
2652  return 1;
2653 }
static int luaCB_autostarted ( lua_State L)
static

Definiert in Zeile 1343 der Datei luascript.c.

1344 {
1346  return 1;
1347 }
static int luaCB_av96_to_aperture ( lua_State L)
static

Definiert in Zeile 2655 der Datei luascript.c.

2656 {
2658  return 1;
2659 }
static int luaCB_bitand ( lua_State L)
static

Definiert in Zeile 1722 der Datei luascript.c.

1723 {
1724  int v1 = (luaL_checknumber(L,1));
1725  int v2 = (luaL_checknumber(L,2));
1726  lua_pushnumber( L, v1 & v2 );
1727  return 1;
1728 }
static int luaCB_bitnot ( lua_State L)
static

Definiert in Zeile 1770 der Datei luascript.c.

1771 {
1772  unsigned val = (luaL_checknumber(L,1));
1773  lua_pushnumber( L, ~val );
1774  return 1;
1775 }
static int luaCB_bitor ( lua_State L)
static

Definiert in Zeile 1730 der Datei luascript.c.

1731 {
1732  int v1 = (luaL_checknumber(L,1));
1733  int v2 = (luaL_checknumber(L,2));
1734  lua_pushnumber( L, v1 | v2 );
1735  return 1;
1736 }
static int luaCB_bitshl ( lua_State L)
static

Definiert in Zeile 1746 der Datei luascript.c.

1747 {
1748  int val = (luaL_checknumber(L,1));
1749  unsigned shift = (luaL_checknumber(L,2));
1750  lua_pushnumber( L, val << shift );
1751  return 1;
1752 }
static int luaCB_bitshri ( lua_State L)
static

Definiert in Zeile 1754 der Datei luascript.c.

1755 {
1756  int val = (luaL_checknumber(L,1));
1757  unsigned shift = (luaL_checknumber(L,2));
1758  lua_pushnumber( L, val >> shift );
1759  return 1;
1760 }
static int luaCB_bitshru ( lua_State L)
static

Definiert in Zeile 1762 der Datei luascript.c.

1763 {
1764  unsigned val = (luaL_checknumber(L,1));
1765  unsigned shift = (luaL_checknumber(L,2));
1766  lua_pushnumber( L, val >> shift );
1767  return 1;
1768 }
static int luaCB_bitxor ( lua_State L)
static

Definiert in Zeile 1738 der Datei luascript.c.

1739 {
1740  int v1 = (luaL_checknumber(L,1));
1741  int v2 = (luaL_checknumber(L,2));
1742  lua_pushnumber( L, v1 ^ v2 );
1743  return 1;
1744 }
static int luaCB_call_event_proc ( lua_State L)
static

Definiert in Zeile 2191 der Datei luascript.c.

2192 {
2194  {
2195  const char *evpname;
2196  unsigned *argbuf;
2197  unsigned n_args = lua_gettop(L);
2198 
2199  evpname=luaL_checkstring( L, 1 );
2200 
2201  argbuf=malloc(n_args * 4);
2202  if (!argbuf)
2203  {
2204  return luaL_error( L, "malloc fail" );
2205  }
2206 
2207  // event proc name is first arg
2208  *argbuf = (unsigned)evpname;
2209 
2210  if(!pack_native_args(L,2,argbuf+1))
2211  {
2212  free(argbuf);
2213  return luaL_error( L, "expected string or number" );
2214  }
2215 
2217  free(argbuf);
2218  return 1;
2219  }
2220  return luaL_error( L, "native calls disabled" );
2221 }
static int luaCB_call_func_ptr ( lua_State L)
static

Definiert in Zeile 2137 der Datei luascript.c.

2138 {
2140  {
2141  unsigned *argbuf=NULL;
2142  unsigned n_args = lua_gettop(L)-1;
2143  void *fptr;
2144 
2145  fptr=(void *)luaL_checknumber( L, 1 );
2146 
2147  if (n_args)
2148  {
2149  argbuf=malloc(n_args * 4);
2150  if(!argbuf)
2151  {
2152  return luaL_error( L, "malloc fail" );
2153  }
2154  if(!pack_native_args(L, 2, argbuf))
2155  {
2156  free(argbuf);
2157  return luaL_error( L, "expected string or number" );
2158  }
2159  }
2160 
2161  lua_pushnumber( L, call_func_ptr(fptr, argbuf, n_args) );
2162  free(argbuf);
2163  return 1;
2164  }
2165  return luaL_error( L, "native calls disabled" );
2166 }
static int luaCB_cls ( lua_State L)
static

Definiert in Zeile 489 der Datei luascript.c.

490 {
491  console_clear();
492  return 0;
493 }
static int luaCB_console_redraw ( lua_State L)
static

Definiert in Zeile 507 der Datei luascript.c.

508 {
509  console_redraw();
510  return 0;
511 }
static int luaCB_draw_clear ( lua_State L)
static

Definiert in Zeile 1324 der Datei luascript.c.

1324  {
1325  draw_restore();
1326  return 0;
1327 }
static int luaCB_draw_ellipse ( lua_State L)
static

Definiert in Zeile 1286 der Datei luascript.c.

1286  {
1287  coord x1=luaL_checknumber(L,1);
1288  coord y1=luaL_checknumber(L,2);
1289  coord a=luaL_checknumber(L,3);
1290  coord b=luaL_checknumber(L,4);
1292  draw_ellipse(x1,y1,a,b,cl,0);
1293  return 0;
1294 }
static int luaCB_draw_ellipse_filled ( lua_State L)
static

Definiert in Zeile 1296 der Datei luascript.c.

1296  {
1297  coord x1=luaL_checknumber(L,1);
1298  coord y1=luaL_checknumber(L,2);
1299  coord a=luaL_checknumber(L,3);
1300  coord b=luaL_checknumber(L,4);
1302  draw_ellipse(x1,y1,a,b,cl,DRAW_FILLED);
1303  return 0;
1304 }
static int luaCB_draw_line ( lua_State L)
static

Definiert in Zeile 1253 der Datei luascript.c.

1253  {
1254  coord x1=luaL_checknumber(L,1);
1255  coord y1=luaL_checknumber(L,2);
1256  coord x2=luaL_checknumber(L,3);
1257  coord y2=luaL_checknumber(L,4);
1259  draw_line(x1,y1,x2,y2,cl);
1260  return 0;
1261 }
static int luaCB_draw_pixel ( lua_State L)
static

Definiert in Zeile 1245 der Datei luascript.c.

1245  {
1246  coord x1=luaL_checknumber(L,1);
1247  coord y1=luaL_checknumber(L,2);
1249  draw_pixel(x1,y1,cl);
1250  return 0;
1251 }
static int luaCB_draw_rect ( lua_State L)
static

Definiert in Zeile 1263 der Datei luascript.c.

1263  {
1264  coord x1=luaL_checknumber(L,1);
1265  coord y1=luaL_checknumber(L,2);
1266  coord x2=luaL_checknumber(L,3);
1267  coord y2=luaL_checknumber(L,4);
1269  int th=luaL_optnumber(L,6,1) & RECT_BORDER_MASK;
1270  draw_rectangle(x1,y1,x2,y2,MAKE_COLOR(cl,cl),th);
1271  return 0;
1272 }
static int luaCB_draw_rect_filled ( lua_State L)
static

Definiert in Zeile 1274 der Datei luascript.c.

1274  {
1275  coord x1 =luaL_checknumber(L,1);
1276  coord y1 =luaL_checknumber(L,2);
1277  coord x2 =luaL_checknumber(L,3);
1278  coord y2 =luaL_checknumber(L,4);
1281  int th =luaL_optnumber(L,7,1) & RECT_BORDER_MASK;
1282  draw_rectangle(x1,y1,x2,y2,MAKE_COLOR(clb,clf),th|DRAW_FILLED);
1283  return 0;
1284 }
static int luaCB_draw_string ( lua_State L)
static

Definiert in Zeile 1306 der Datei luascript.c.

1307 {
1308  coord x1 = luaL_checknumber(L,1);
1309  coord y1 = luaL_checknumber(L,2);
1310  const char *t = luaL_checkstring( L, 3 );
1313  int xsize = luaL_optnumber(L,6,1);
1314  int ysize = luaL_optnumber(L,7,xsize);
1315 
1316  if ((xsize <= 1) && (ysize <= 1))
1317  draw_string(x1, y1, t, MAKE_COLOR(clb,clf));
1318  else
1319  draw_string_scaled(x1, y1, t, MAKE_COLOR(clb,clf), xsize, ysize);
1320 
1321  return 0;
1322 }
static int luaCB_enter_alt ( lua_State L)
static

Definiert in Zeile 1395 der Datei luascript.c.

1396 {
1397  enter_alt();
1398  // if alt explicitly changed by script, set as 'saved' state
1399  if(lua_script_is_ptp) {
1400  ptp_saved_alt_state = 1;
1401  }
1402  return 0;
1403 }
static int luaCB_exit_alt ( lua_State L)
static

Definiert in Zeile 1405 der Datei luascript.c.

1406 {
1407  exit_alt();
1408  // if alt explicitly changed by script, set as 'saved' state
1409  if(lua_script_is_ptp) {
1410  ptp_saved_alt_state = 0;
1411  }
1412  return 0;
1413 }
static int luaCB_file_browser ( lua_State L)
static

Definiert in Zeile 1212 der Datei luascript.c.

1212  {
1213  // Disconnect button input from script so buttons will work in file browser
1215  // Push file browser action onto stack - will loop doing nothing until file browser exits
1217  // Switch to file browser gui mode. Path can be supplied in call or defaults to "A" (root directory).
1219  // Yield the script so that the action stack will process the AS_FILE_BROWSER action
1220  return lua_yield(L, 0);
1221 }
static int luaCB_get_alt_mode ( lua_State L)
static

Definiert in Zeile 1415 der Datei luascript.c.

1416 {
1418  return 1 ;
1419 }
static int luaCB_get_autostart ( lua_State L)
static

Definiert in Zeile 1349 der Datei luascript.c.

1350 {
1352  return 1;
1353 }
static int luaCB_get_av96 ( lua_State L)
static

Definiert in Zeile 549 der Datei luascript.c.

550 {
552  return 1;
553 }
static int luaCB_get_buildinfo ( lua_State L)
static

Definiert in Zeile 1789 der Datei luascript.c.

1790 {
1791  lua_createtable(L, 0, 9);
1792  set_string_field( L,"platform", camera_info.platform );
1793  set_string_field( L,"platsub", camera_info.platformsub );
1794  set_string_field( L,"version", camera_info.chdk_ver );
1795  set_string_field( L,"build_number", camera_info.build_number );
1796  set_string_field( L,"build_revision", camera_info.build_svnrev );
1797  set_string_field( L,"build_date", camera_info.build_date );
1798  set_string_field( L,"build_time", camera_info.build_time );
1799  set_string_field( L,"os", camera_info.os );
1800  set_number_field( L,"platformid", conf.platformid );
1801  return 1;
1802 }
static int luaCB_get_bv96 ( lua_State L)
static

Definiert in Zeile 555 der Datei luascript.c.

556 {
558  return 1;
559 }
static int luaCB_get_config_value ( lua_State L)
static

Definiert in Zeile 2234 der Datei luascript.c.

2234  {
2235  unsigned int argc = lua_gettop(L);
2236  unsigned int id, i;
2237  int ret = 1;
2238  tConfigVal configVal;
2239 
2240  if( argc>=1 ) {
2241  id = luaL_checknumber(L, 1);
2242  switch( conf_getValue(id, &configVal) ) {
2243  case CONF_VALUE:
2244  lua_pushnumber(L, configVal.numb);
2245  break;
2246  case CONF_INT_PTR:
2247  lua_createtable(L, 0, configVal.numb);
2248  for( i=0; i<configVal.numb; i++ ) {
2249  lua_pushinteger(L, configVal.pInt[i]);
2250  lua_rawseti(L, -2, i+1); //t[i+1]=configVal.pInt[i]
2251  }
2252  break;
2253  case CONF_CHAR_PTR:
2254  lua_pushstring(L, configVal.str);
2255  break;
2256  case CONF_OSD_POS:
2257  lua_pushnumber(L, configVal.pos.x);
2258  lua_pushnumber(L, configVal.pos.y); ret++;
2259  break;
2260  default:
2261  if( argc>=2) { //Default
2262  ret = argc-1;
2263  } else {
2264  lua_pushnil(L);
2265  }
2266  break;
2267  }
2268  } else {
2269  lua_pushnil(L);
2270  }
2271  return ret;
2272 }
static int luaCB_get_current_av96 ( lua_State L)
static

Definiert in Zeile 752 der Datei luascript.c.

753 {
755  return 1;
756 }
static int luaCB_get_current_tv96 ( lua_State L)
static

Definiert in Zeile 760 der Datei luascript.c.

761 {
762  long tv = shooting_get_current_tv96();
763  if( tv == SHOOTING_TV96_INVALID) {
764  lua_pushnil(L);
765  } else {
766  lua_pushnumber( L, tv);
767  }
768  return 1;
769 }
static int luaCB_get_curve_file ( lua_State L)
static

Definiert in Zeile 402 der Datei luascript.c.

403 {
405  return 1;
406 }
static int luaCB_get_curve_state ( lua_State L)
static

Definiert in Zeile 388 der Datei luascript.c.

389 {
391  return 1;
392 }
static int luaCB_get_day_seconds ( lua_State L)
static

Definiert in Zeile 561 der Datei luascript.c.

562 {
563  struct tm *ttm;
564  ttm = get_localtime();
565  lua_pushnumber( L, ttm->tm_hour * 3600 + ttm->tm_min * 60 + ttm->tm_sec );
566  return 1;
567 }
static int luaCB_get_disk_size ( lua_State L)
static

Definiert in Zeile 569 der Datei luascript.c.

570 {
572  return 1;
573 }
static int luaCB_get_dofinfo ( lua_State L)
static
static int luaCB_get_draw_title_line ( lua_State L)
static

Definiert in Zeile 1873 der Datei luascript.c.

1874 {
1876  return 1;
1877 }
static int luaCB_get_drive_mode ( lua_State L)
static

Definiert in Zeile 1463 der Datei luascript.c.

1464 {
1466  return 1;
1467 }
static int luaCB_get_ev ( lua_State L)
static

Definiert in Zeile 1547 der Datei luascript.c.

1548 {
1550  return 1;
1551 }
static int luaCB_get_exp_count ( lua_State L)
static

Definiert in Zeile 695 der Datei luascript.c.

696 {
698  return 1;
699 }
static int luaCB_get_flash_mode ( lua_State L)
static

Definiert in Zeile 1487 der Datei luascript.c.

1488 {
1490  return 1;
1491 }
static int luaCB_get_flash_params_count ( lua_State L)
static

Definiert in Zeile 847 der Datei luascript.c.

848 {
850  return 1;
851 }
static int luaCB_get_flash_ready ( lua_State L)
static

Definiert in Zeile 1499 der Datei luascript.c.

1500 {
1502  return 1;
1503 }
static int luaCB_get_focus ( lua_State L)
static

Definiert in Zeile 600 der Datei luascript.c.

601 {
603  return 1;
604 }
static int luaCB_get_focus_mode ( lua_State L)
static

Definiert in Zeile 1469 der Datei luascript.c.

1470 {
1472  return 1;
1473 }
static int luaCB_get_focus_ok ( lua_State L)
static

Definiert in Zeile 1481 der Datei luascript.c.

1482 {
1484  return 1;
1485 }
static int luaCB_get_focus_state ( lua_State L)
static

Definiert in Zeile 1475 der Datei luascript.c.

1476 {
1478  return 1;
1479 }
static int luaCB_get_free_disk_space ( lua_State L)
static

Definiert in Zeile 594 der Datei luascript.c.

595 {
597  return 1;
598 }
static int luaCB_get_gui_screen_height ( lua_State L)
static

Definiert in Zeile 1337 der Datei luascript.c.

1338 {
1340  return 1;
1341 }
static int luaCB_get_gui_screen_width ( lua_State L)
static

Definiert in Zeile 1331 der Datei luascript.c.

1332 {
1334  return 1;
1335 }
static int luaCB_get_histo_range ( lua_State L)
static

Definiert in Zeile 1562 der Datei luascript.c.

1563 {
1564  int from = (luaL_checknumber(L,1));
1565  int to = (luaL_checknumber(L,2));
1567  return 1;
1568 }
static int luaCB_get_image_dir ( lua_State L)
static

Definiert in Zeile 701 der Datei luascript.c.

702 {
703  char dir[32];
704  get_target_dir_name(dir);
705  lua_pushstring( L, dir );
706  return 1;
707 }
static int luaCB_get_imager_active ( lua_State L)
static

Definiert in Zeile 786 der Datei luascript.c.

787 {
789  return 1;
790 }
static int luaCB_get_IS_mode ( lua_State L)
static

Definiert in Zeile 1505 der Datei luascript.c.

1506 {
1508  return 1;
1509 }
static int luaCB_get_iso_market ( lua_State L)
static

Definiert in Zeile 606 der Datei luascript.c.

607 {
609  return 1;
610 }
static int luaCB_get_iso_mode ( lua_State L)
static

Definiert in Zeile 612 der Datei luascript.c.

613 {
615  return 1;
616 }
static int luaCB_get_iso_real ( lua_State L)
static

Definiert in Zeile 618 der Datei luascript.c.

619 {
621  return 1;
622 }
static int luaCB_get_jpg_count ( lua_State L)
static

Definiert in Zeile 624 der Datei luascript.c.

625 {
626  lua_pushnumber( L, GetJpgCount() );
627  return 1;
628 }
static int luaCB_get_levent_def ( lua_State L)
static

Definiert in Zeile 1923 der Datei luascript.c.

1924 {
1925  unsigned event_index = levent_index_from_id_lua_arg(L,1);
1926  if (event_index == LEVENT_INVALID_INDEX) {
1927  lua_pushnil(L);
1928  return 1;
1929  }
1930  lua_pushstring(L, levent_table[event_index].name);
1931  lua_pushnumber(L, levent_table[event_index].id);
1932  lua_pushnumber(L, levent_table[event_index].param);
1933  return 3;
1934 }
static int luaCB_get_levent_def_by_index ( lua_State L)
static

Definiert in Zeile 1958 der Datei luascript.c.

1959 {
1960  unsigned i = luaL_checknumber(L,1);
1961  if(i >= levent_count()) {
1962  lua_pushnil(L);
1963  return 1;
1964  }
1965  lua_pushstring(L, levent_table[i].name);
1966  lua_pushnumber(L, levent_table[i].id);
1967  lua_pushnumber(L, levent_table[i].param);
1968  return 3;
1969 }
static int luaCB_get_levent_index ( lua_State L)
static

Definiert in Zeile 1941 der Datei luascript.c.

1942 {
1943  unsigned event_index = levent_index_from_id_lua_arg(L,1);
1944  if (event_index == LEVENT_INVALID_INDEX) {
1945  lua_pushnil(L);
1946  }
1947  else {
1948  lua_pushnumber(L, event_index);
1949  }
1950  return 1;
1951 }
static int luaCB_get_live_histo ( lua_State L)
static

Definiert in Zeile 1588 der Datei luascript.c.

1589 {
1590  unsigned short *h = malloc(256*sizeof(short));
1591  if(!h) {
1592  return luaL_error(L,"malloc fail");
1593  }
1594  int total=live_histogram_read_y(h);
1595  lua_createtable(L, 0, 256);
1596  int i;
1597  for(i=0;i<256;i++) {
1598  lua_pushnumber(L,h[i]);
1599  lua_rawseti(L,-2,i);
1600  }
1601  free(h);
1602  lua_pushnumber(L,total);
1603  return 2;
1604 }
static int luaCB_get_max_av96 ( lua_State L)
static

Definiert in Zeile 740 der Datei luascript.c.

741 {
742  short av=shooting_get_max_av96();
743  if(av < 0) { // -1 = Av not available
744  lua_pushnil(L);
745  } else {
746  lua_pushnumber( L, av );
747  }
748  return 1;
749 }
static int luaCB_get_meminfo ( lua_State L)
static

Definiert in Zeile 2484 der Datei luascript.c.

2484  {
2485  const char *heapname = luaL_optstring( L, 1, "combined" );
2486  cam_meminfo meminfo;
2487  if (strcmp(heapname,"combined") == 0) {
2488  GetCombinedMemInfo(&meminfo);
2489  meminfo.start_address=meminfo.end_address=-1; // not meaningful
2490  }
2491  else if (strcmp(heapname,"system") == 0)
2492  {
2493  GetMemInfo(&meminfo);
2494  }
2495  else if ((strcmp(heapname,"aram") == 0))
2496  {
2497  if(!GetARamInfo(&meminfo)) {
2498  lua_pushboolean(L,0);
2499  return 1;
2500  }
2501  }
2502  else if (strcmp(heapname,"exmem") == 0)
2503  {
2504  if(!GetExMemInfo(&meminfo)) {;
2505  lua_pushboolean(L,0);
2506  return 1;
2507  }
2508  }
2509  else
2510  {
2511  lua_pushboolean(L,0);
2512  return 1;
2513  }
2514  // adjust start and size, if CHDK is loaded at heap start
2515  if(meminfo.start_address == camera_info.text_start) {
2517  meminfo.total_size -= camera_info.memisosize;
2518  }
2519  lua_createtable(L, 0, 13); // might not always use 13, but doesn't hurt
2520  set_string_field( L,"name", heapname );
2521  // CHDK allocates from all available heaps now
2522  lua_pushboolean( L, 1);
2523  lua_setfield(L, -2, "chdk_malloc");
2524  set_number_field( L, "chdk_start", camera_info.text_start);
2525  set_number_field( L, "chdk_size", camera_info.memisosize );
2526  set_meminfo_num( L, "start_address", meminfo.start_address );
2527  set_meminfo_num( L, "end_address", meminfo.end_address);
2528  set_meminfo_num( L, "total_size", meminfo.total_size);
2529  set_meminfo_num( L, "allocated_size", meminfo.allocated_size);
2530  set_meminfo_num( L, "allocated_peak", meminfo.allocated_peak);
2531  set_meminfo_num( L, "allocated_count", meminfo.allocated_count);
2532  set_meminfo_num( L, "free_size", meminfo.free_size);
2533  set_meminfo_num( L, "free_block_max_size", meminfo.free_block_max_size);
2534  set_meminfo_num( L, "free_block_count", meminfo.free_block_count);
2535  return 1;
2536 }
static int luaCB_get_min_av96 ( lua_State L)
static

Definiert in Zeile 728 der Datei luascript.c.

729 {
730  short av=shooting_get_min_av96();
731  if(av < 0) { // -1 = Av not available
732  lua_pushnil(L);
733  } else {
734  lua_pushnumber( L, av );
735  }
736  return 1;
737 }
static int luaCB_get_mode ( lua_State L)
static

Definiert in Zeile 1804 der Datei luascript.c.

1805 {
1809  return 3;
1810 }
static int luaCB_get_movie_status ( lua_State L)
static

Definiert in Zeile 1439 der Datei luascript.c.

1440 {
1442  return 1;
1443 }
static int luaCB_get_nd_current_ev96 ( lua_State L)
static

Definiert in Zeile 779 der Datei luascript.c.

780 {
782  return 1;
783 }
static int luaCB_get_nd_present ( lua_State L)
static

Definiert in Zeile 1523 der Datei luascript.c.

1524 {
1525  int to;
1526  if (camera_info.cam_has_nd_filter == 0)
1527  {
1528  to = 0;
1529  }
1530  else
1531  {
1533  to = 1;
1534  else
1535  to = 2;
1536  }
1537  lua_pushnumber( L, to );
1538  return 1;
1539 }
static int luaCB_get_nd_value_ev96 ( lua_State L)
static

Definiert in Zeile 772 der Datei luascript.c.

773 {
775  return 1;
776 }
static int luaCB_get_orientation_sensor ( lua_State L)
static

Definiert in Zeile 1511 der Datei luascript.c.

1512 {
1514  return 1;
1515 }
static int luaCB_get_parameter_data ( lua_State L)
static

Definiert in Zeile 816 der Datei luascript.c.

817 {
818  unsigned size;
819  unsigned id = luaL_checknumber( L, 1 );
820  unsigned val;
821 
822  size = get_parameter_size(id);
823  if (size == 0) {
824  // return nil
825  return 0;
826  }
827  if (size >= 1 && size <= 4) {
828  val = 0;
829  get_parameter_data( id, &val, size );
830  lua_pushlstring( L, (char *)&val, size );
831  // for convenience, params that fit in a number are returned in one as a second result
832  lua_pushnumber( L, val );
833  return 2;
834  }
835  else {
836  char *buf = malloc(size);
837  if(!buf) {
838  luaL_error( L, "malloc failed in luaCB_get_parameter_data" );
839  }
840  get_parameter_data( id, buf, size );
841  lua_pushlstring( L, buf, size );
842  free(buf);
843  return 1;
844  }
845 }
static int luaCB_get_partitionInfo ( lua_State L)
static

Definiert in Zeile 513 der Datei luascript.c.

514 {
516  {
517  lua_createtable(L, 0, 4);
518  SET_INT_FIELD("count", get_part_count());
519  SET_INT_FIELD("active", get_active_partition());
520  SET_INT_FIELD("type", get_part_type());
521  SET_INT_FIELD("size", GetTotalCardSpaceKb()>>10);
522  return 1;
523  }
524  return 0;
525 }
static int luaCB_get_prop ( lua_State L)
static

Definiert in Zeile 635 der Datei luascript.c.

636 {
638  return 1;
639 }
static int luaCB_get_prop_str ( lua_State L)
static

Definiert in Zeile 647 der Datei luascript.c.

647  {
648  void *buf;
649  unsigned size;
650  unsigned prop_id = luaL_checknumber( L, 1 );
651  size = luaL_checknumber( L, 2 );
652  buf = malloc(size);
653  if(!buf) {
654  return luaL_error( L, "malloc failed in luaCB_get_prop" );
655  }
656  if(get_property_case(prop_id,buf,size) == 0) {
657  lua_pushlstring( L, buf, size );
658  } else {
659  lua_pushboolean( L, 0);
660  }
661  free(buf);
662  return 1;
663 }
static int luaCB_get_propset ( lua_State L)
static

Definiert in Zeile 1541 der Datei luascript.c.

1542 {
1544  return 1;
1545 }
static int luaCB_get_raw ( lua_State L)
static

Definiert in Zeile 976 der Datei luascript.c.

977 {
979  return 1;
980 }
static int luaCB_get_raw_count ( lua_State L)
static

Definiert in Zeile 677 der Datei luascript.c.

678 {
679  lua_pushnumber( L, GetRawCount() );
680  return 1;
681 }
static int luaCB_get_raw_nr ( lua_State L)
static

Definiert in Zeile 964 der Datei luascript.c.

965 {
966  lua_pushnumber( L, conf.raw_nr );
967  return 1;
968 }
static int luaCB_get_raw_support ( lua_State L)
static

Definiert in Zeile 671 der Datei luascript.c.

672 {
674  return 1;
675 }
static int luaCB_get_sd_over_modes ( lua_State L)
static

Definiert in Zeile 433 der Datei luascript.c.

434 {
436  return 1;
437 }
static int luaCB_get_shooting ( lua_State L)
static

Definiert in Zeile 1493 der Datei luascript.c.

1494 {
1496  return 1;
1497 }
static int luaCB_get_sv96 ( lua_State L)
static

Definiert in Zeile 683 der Datei luascript.c.

684 {
686  return 1;
687 }
static int luaCB_get_temperature ( lua_State L)
static

Definiert in Zeile 1612 der Datei luascript.c.

1613 {
1614  int which = (luaL_checknumber( L, 1 ));
1615  int temp = -100; // do something insane if users passes bad value
1616  switch (which)
1617  {
1618  case 0:
1619  temp = get_optical_temp();
1620  break;
1621  case 1:
1622  temp = get_ccd_temp();
1623  break;
1624  case 2:
1625  temp = get_battery_temp();
1626  break;
1627  }
1628  lua_pushnumber( L, temp );
1629  return 1;
1630 }
static int luaCB_get_tick_count ( lua_State L)
static

Definiert in Zeile 689 der Datei luascript.c.

690 {
692  return 1;
693 }
static int luaCB_get_time ( lua_State L)
static

Definiert in Zeile 1632 der Datei luascript.c.

1633 {
1634  int r = -1;
1635  static struct tm *ttm;
1636  ttm = get_localtime();
1637  const char *t = luaL_checkstring( L, 1 );
1638  if (strncmp("s", t, 1)==0) r = ( L, ttm->tm_sec );
1639  else if (strncmp("m", t, 1)==0) r = ( L, ttm->tm_min );
1640  else if (strncmp("h", t, 1)==0) r = ( L, ttm->tm_hour );
1641  else if (strncmp("D", t, 1)==0) r = ( L, ttm->tm_mday );
1642  else if (strncmp("M", t, 1)==0) r = ( L, ttm->tm_mon+1 );
1643  else if (strncmp("Y", t, 1)==0) r = ( L, 1900+ttm->tm_year );
1644  lua_pushnumber( L, r );
1645  return 1;
1646 }
static int luaCB_get_tv96 ( lua_State L)
static

Definiert in Zeile 709 der Datei luascript.c.

710 {
712  return 1;
713 }
static int luaCB_get_usb_capture_support ( lua_State L)
static

Definiert in Zeile 2559 der Datei luascript.c.

2560 {
2562  return 1;
2563 }
static int luaCB_get_usb_capture_target ( lua_State L)
static

Definiert in Zeile 2586 der Datei luascript.c.

2587 {
2589  return 1;
2590 }
static int luaCB_get_usb_power ( lua_State L)
static

Definiert in Zeile 1364 der Datei luascript.c.

1365 {
1366  lua_pushnumber( L, get_usb_power(luaL_optnumber( L, 1, 0 )) );
1367  return 1;
1368 }
static int luaCB_get_user_av96 ( lua_State L)
static

Definiert in Zeile 721 der Datei luascript.c.

722 {
724  return 1;
725 }
static int luaCB_get_user_av_id ( lua_State L)
static

Definiert in Zeile 715 der Datei luascript.c.

716 {
718  return 1;
719 }
static int luaCB_get_user_tv96 ( lua_State L)
static

Definiert in Zeile 798 der Datei luascript.c.

799 {
801  return 1;
802 }
static int luaCB_get_user_tv_id ( lua_State L)
static

Definiert in Zeile 792 der Datei luascript.c.

793 {
795  return 1;
796 }
static int luaCB_get_vbatt ( lua_State L)
static

Definiert in Zeile 804 der Datei luascript.c.

805 {
807  return 1;
808 }
static int luaCB_get_video_button ( lua_State L)
static

Definiert in Zeile 1451 der Datei luascript.c.

1452 {
1454  return 1;
1455 }
static int luaCB_get_video_recording ( lua_State L)
static

Definiert in Zeile 1457 der Datei luascript.c.

1458 {
1460  return 1;
1461 }
static int luaCB_get_zoom ( lua_State L)
static

Definiert in Zeile 810 der Datei luascript.c.

811 {
813  return 1;
814 }
static int luaCB_get_zoom_steps ( lua_State L)
static

Definiert in Zeile 1517 der Datei luascript.c.

1518 {
1520  return 1;
1521 }
static int luaCB_init_usb_capture ( lua_State L)
static

Definiert in Zeile 2573 der Datei luascript.c.

2574 {
2575  int what=luaL_checknumber(L, 1);
2576  int startline=luaL_optnumber(L, 2, 0);
2577  int numlines=luaL_optnumber(L, 3, 0);
2578  lua_pushboolean(L,remotecap_set_target(what,startline,numlines));
2579  return 1;
2580 }
static int luaCB_is_capture_mode_valid ( lua_State L)
static

Definiert in Zeile 2060 der Datei luascript.c.

2061 {
2062  int modenum = luaL_checknumber(L,1);
2063  lua_pushboolean( L, shooting_mode_chdk2canon(modenum) != -1 );
2064  return 1;
2065 }
static int luaCB_is_key ( lua_State L)
static

Definiert in Zeile 1104 der Datei luascript.c.

1105 {
1107  return 1;
1108 }
static int luaCB_is_pressed ( lua_State L)
static

Definiert in Zeile 1098 der Datei luascript.c.

1099 {
1101  return 1;
1102 }
static int luaCB_iso_market_to_real ( lua_State L)
static

Definiert in Zeile 2631 der Datei luascript.c.

2632 {
2634  return 1;
2635 }
static int luaCB_iso_real_to_market ( lua_State L)
static

Definiert in Zeile 2625 der Datei luascript.c.

2626 {
2628  return 1;
2629 }
static int luaCB_iso_to_sv96 ( lua_State L)
static

Definiert in Zeile 2613 der Datei luascript.c.

2614 {
2616  return 1;
2617 }
static int luaCB_keyfunc ( lua_State L)
static

Definiert in Zeile 482 der Datei luascript.c.

483 {
484  void* func = lua_touserdata( L, lua_upvalueindex(1) );
485  ((void(*)(long))func)( lua_get_key_arg( L, 1 ) );
486  return lua_yield( L, 0 );
487 }
static int luaCB_load_config_file ( lua_State L)
static

Definiert in Zeile 2338 der Datei luascript.c.

2338  {
2340  return 1;
2341 }
static int luaCB_md_af_led_control ( lua_State L)
static

Definiert in Zeile 1129 der Datei luascript.c.

1130 {
1133  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
1134  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
1135  // clear previous values
1137  camera_info.perf.af_led.min = 0xFFFFFFFF;
1138  } else {
1139  camera_info.perf.md_af_tuning = 0; // Disable MD testing
1140  }
1141  return 0;
1142 }
static int luaCB_md_detect_motion ( lua_State L)
static

Definiert in Zeile 1157 der Datei luascript.c.

1158 {
1159  int columns = (luaL_optnumber(L,1,6));
1160  int rows = (luaL_optnumber(L,2,4));
1161  int pixel_measure_mode = (luaL_optnumber(L,3,1));
1162  int detection_timeout = (luaL_optnumber(L,4,10000));
1163  int measure_interval = (luaL_optnumber(L,5,7));
1164  int threshold = (luaL_optnumber(L,6,10));
1165  int draw_grid = (luaL_optnumber(L,7,1));
1166  // arg 8 is the return value in ubasic. We
1167  // ignore it here. - AUJ
1168  int clipping_region_mode = (luaL_optnumber(L,9,0));
1169  int clipping_region_column1 = (luaL_optnumber(L,10,0));
1170  int clipping_region_row1 = (luaL_optnumber(L,11,0));
1171  int clipping_region_column2 = (luaL_optnumber(L,12,0));
1172  int clipping_region_row2 = (luaL_optnumber(L,13,0));
1173  int parameters = (luaL_optnumber(L,14,1));
1174  int pixels_step = (luaL_optnumber(L,15,6));
1175  int msecs_before_trigger = (luaL_optnumber(L,16,0));
1176 
1178  columns, rows, pixel_measure_mode, detection_timeout,
1179  measure_interval, threshold, draw_grid,
1180  clipping_region_mode,
1181  clipping_region_column1, clipping_region_row1,
1182  clipping_region_column2, clipping_region_row2,
1183  parameters, pixels_step, msecs_before_trigger
1184  ))
1185  return lua_yield(L, 0);
1186  else
1187  return luaL_error( L, "md_init_motion_detector failed" );
1188 }
static int luaCB_md_get_cell_diff ( lua_State L)
static

Definiert in Zeile 1144 der Datei luascript.c.

1145 {
1147  return 1;
1148 }
static int luaCB_md_get_cell_val ( lua_State L)
static

Definiert in Zeile 1151 der Datei luascript.c.

1152 {
1154  return 1;
1155 }
static int luaCB_peek ( lua_State L)
static

Definiert in Zeile 1652 der Datei luascript.c.

1653 {
1654  unsigned addr = luaL_checknumber(L,1);
1655  unsigned size = luaL_optnumber(L, 2, 4);
1656  switch(size) {
1657  case 1:
1658  lua_pushnumber( L, *(unsigned char *)(addr) );
1659  break;
1660  case 2:
1661  if (addr & 0x1) {
1662  lua_pushnil(L);
1663  }
1664  else {
1665  lua_pushnumber( L, *(unsigned short *)(addr) );
1666  }
1667  break;
1668  case 4:
1669  if (addr & 0x3) {
1670  lua_pushnil(L);
1671  }
1672  else {
1673  lua_pushnumber( L, *(unsigned *)(addr) );
1674  }
1675  break;
1676  default:
1677  lua_pushnil(L);
1678 
1679  }
1680  return 1;
1681 }
static int luaCB_play_sound ( lua_State L)
static

Definiert in Zeile 1606 der Datei luascript.c.

1607 {
1608  play_sound(luaL_checknumber( L, 1 ));
1609  return 0;
1610 }
static int luaCB_poke ( lua_State L)
static

Definiert in Zeile 1689 der Datei luascript.c.

1690 {
1691  unsigned addr = luaL_checknumber(L,1);
1692  unsigned val = luaL_checknumber(L,2);
1693  unsigned size = luaL_optnumber(L, 3, 4);
1694  int status = 0;
1695  switch(size) {
1696  case 1:
1697  *(unsigned char *)(addr) = (unsigned char)val;
1698  status=1;
1699  break;
1700  case 2:
1701  if (!(addr & 0x1)) {
1702  *(unsigned short *)(addr) = (unsigned short)val;
1703  status=1;
1704  }
1705  break;
1706  case 4:
1707  if (!(addr & 0x3)) {
1708  *(unsigned *)(addr) = val;
1709  status=1;
1710  }
1711  break;
1712  }
1713  if(status) {
1714  lua_pushboolean(L,1);
1715  }
1716  else {
1717  lua_pushnil(L);
1718  }
1719  return 1;
1720 }
static int luaCB_post_levent_for_npt ( lua_State L)
static

Definiert in Zeile 1990 der Datei luascript.c.

1991 {
1992  unsigned event_id,arg;
1993 
1994  event_id = levent_id_from_lua_arg(L,1);
1995  arg = luaL_optnumber(L, 2, 0);
1996  PostLogicalEventForNotPowerType(event_id,arg);
1997  return 0;
1998 }
static int luaCB_post_levent_to_ui ( lua_State L)
static

Definiert in Zeile 1980 der Datei luascript.c.

1981 {
1982  unsigned event_id,arg;
1983 
1984  event_id = levent_id_from_lua_arg(L,1);
1985  arg = luaL_optnumber(L, 2, 0);
1986  PostLogicalEventToUI(event_id,arg);
1987  return 0;
1988 }
static int luaCB_print_screen ( lua_State L)
static

Definiert in Zeile 1433 der Datei luascript.c.

1434 {
1436  return 0;
1437 }
static int luaCB_raw_merge_add_file ( lua_State L)
static

Definiert in Zeile 1833 der Datei luascript.c.

1834 {
1836  return 1;
1837 }
static int luaCB_raw_merge_end ( lua_State L)
static

Definiert in Zeile 1839 der Datei luascript.c.

1840 {
1842  return 0;
1843 }
static int luaCB_raw_merge_start ( lua_State L)
static

Definiert in Zeile 1819 der Datei luascript.c.

1820 {
1821  int op = luaL_checknumber(L,1);
1822  if ((op == RAW_OPERATION_SUM || op == RAW_OPERATION_AVERAGE))
1823  {
1825  return 1;
1826  }
1827  else {
1828  return luaL_argerror(L,1,"invalid raw merge op");
1829  }
1830 }
static int luaCB_read_usb_msg ( lua_State L)
static

Definiert in Zeile 2389 der Datei luascript.c.

2390 {
2391  int timeout = sleep_delay(luaL_optnumber(L,1,0));
2392  if (timeout > 0)
2393  {
2394  action_push(timeout);
2396  return lua_yield( L, 0 );
2397  }
2399  if(msg)
2400  {
2401  lua_pushlstring(L,msg->data,msg->size);
2402  free(msg);
2403  return 1;
2404  }
2405  lua_pushnil(L);
2406  return 1;
2407 }
static int luaCB_reboot ( lua_State L)
static

Definiert in Zeile 2228 der Datei luascript.c.

2229 {
2230  lua_pushboolean(L, reboot(luaL_optstring( L, 1, NULL )));
2231  return 1;
2232 }
static int luaCB_save_config_file ( lua_State L)
static

Definiert in Zeile 2333 der Datei luascript.c.

2333  {
2335  return 1;
2336 }
static int luaCB_seconds_to_tv96 ( lua_State L)
static

Definiert in Zeile 2673 der Datei luascript.c.

2674 {
2676  return 1;
2677 }
static int luaCB_set_aelock ( lua_State L)
static

Definiert in Zeile 408 der Datei luascript.c.

409 {
410  int val = on_off_value_from_lua_arg(L, 1);
411  if (val>0) DoAELock(); // 1: enable AELock
412  else UnlockAE(); // 0: disable unlock AE
413  return 0;
414 }
static int luaCB_set_aflock ( lua_State L)
static

Definiert in Zeile 416 der Datei luascript.c.

417 {
418  int val = on_off_value_from_lua_arg(L, 1);
419  if (val>0) DoAFLock(); // 1: enable AFLock
420  else UnlockAF(); // 0: disable unlock AF
421  return 0;
422 }
static int luaCB_set_autostart ( lua_State L)
static

Definiert in Zeile 1355 der Datei luascript.c.

1356 {
1357  int to;
1358  to = luaL_checknumber( L, 1 );
1359  if ( to >= 0 && to <= 3 ) conf.script_startup = to;
1360  conf_save();
1361  return 0;
1362 }
static int luaCB_set_av96 ( lua_State L)
static

Definiert in Zeile 859 der Datei luascript.c.

860 {
862  return 0;
863 }
static int luaCB_set_av96_direct ( lua_State L)
static

Definiert in Zeile 853 der Datei luascript.c.

854 {
856  return 0;
857 }
static int luaCB_set_backlight ( lua_State L)
static

Definiert in Zeile 1846 der Datei luascript.c.

1847 {
1848  int val = on_off_value_from_lua_arg(L,1);
1849 
1850  if (val > 0) TurnOnBackLight();
1851  else TurnOffBackLight();
1852  return 0;
1853 }
static int luaCB_set_capture_mode ( lua_State L)
static

Definiert in Zeile 2048 der Datei luascript.c.

2049 {
2050  int modenum = luaL_checknumber(L,1);
2051  lua_pushboolean( L, shooting_set_mode_chdk(modenum) );
2052  return 1;
2053 }
static int luaCB_set_capture_mode_canon ( lua_State L)
static

Definiert in Zeile 2033 der Datei luascript.c.

2034 {
2035  int modenum = luaL_checknumber(L,1);
2036  // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value
2037  if(modenum < 0)
2038  modenum &= 0xFFFF;
2040  return 1;
2041 }
static int luaCB_set_config_autosave ( lua_State L)
static

Definiert in Zeile 2328 der Datei luascript.c.

2328  {
2330  return 0;
2331 }
static int luaCB_set_config_value ( lua_State L)
static

Definiert in Zeile 2274 der Datei luascript.c.

2274  {
2275  unsigned int argc = lua_gettop(L);
2276  unsigned int id, i, j;
2277  tConfigVal configVal = {0,0,0,0}; //initialize isXXX
2278 
2279  if( argc>=2 ) {
2280  id = luaL_checknumber(L, 1);
2281  for( i=2; i<=argc; i++) {
2282  switch( lua_type(L, i) ) {
2283  case LUA_TNUMBER:
2284  if( !configVal.isNumb ) {
2285  configVal.numb = luaL_checknumber(L, i);
2286  configVal.isNumb++;
2287  }
2288  switch( configVal.isPos ) {
2289  case 0: configVal.pos.x = luaL_checknumber(L, i); configVal.isPos++; break;
2290  case 1: configVal.pos.y = luaL_checknumber(L, i); configVal.isPos++; break;
2291  }
2292  break;
2293  case LUA_TSTRING:
2294  if( !configVal.isStr ) {
2295  configVal.str = (char*)luaL_checkstring(L, i);
2296  configVal.isStr++;
2297  }
2298  break;
2299  case LUA_TTABLE:
2300  if( !configVal.isPInt ) {
2301  configVal.numb = lua_objlen(L, i);
2302  if( configVal.pInt ) {
2303  free(configVal.pInt);
2304  configVal.pInt = NULL;
2305  }
2306  configVal.pInt = malloc(configVal.numb*sizeof(int));
2307  if( configVal.pInt ) {
2308  for( j=1; j<=configVal.numb; j++) {
2309  lua_rawgeti(L, i, j);
2310  configVal.pInt[j-1] = lua_tointeger(L, -1);
2311  lua_pop(L, 1);
2312  }
2313  }
2314  configVal.isPInt++;
2315  }
2316  break;
2317  }
2318  }
2319  lua_pushboolean(L, conf_setValue(id, configVal));
2320  if( configVal.pInt ) {
2321  free(configVal.pInt);
2322  configVal.pInt = NULL;
2323  }
2324  } else lua_pushboolean(L, 0);
2325  return 1;
2326 }
static int luaCB_set_console_autoredraw ( lua_State L)
static

Definiert in Zeile 501 der Datei luascript.c.

502 {
504  return 0;
505 }
static int luaCB_set_console_layout ( lua_State L)
static

Definiert in Zeile 495 der Datei luascript.c.

496 {
498  return 0;
499 }
static int luaCB_set_curve_file ( lua_State L)
static

Definiert in Zeile 394 der Datei luascript.c.

395 {
396  size_t l;
397  const char *s = luaL_checklstring(L, 1, &l);
399  return 0;
400 }
static int luaCB_set_curve_state ( lua_State L)
static

Definiert in Zeile 382 der Datei luascript.c.

383 {
385  return 0;
386 }
static int luaCB_set_draw_title_line ( lua_State L)
static

Definiert in Zeile 1866 der Datei luascript.c.

1867 {
1869  return 0;
1870 }
static int luaCB_set_ev ( lua_State L)
static

Definiert in Zeile 1553 der Datei luascript.c.

1554 {
1555  int to;
1556  to = luaL_checknumber( L, 1 );
1559  return 0;
1560 }
static int luaCB_set_exit_key ( lua_State L)
static

Definiert in Zeile 1110 der Datei luascript.c.

1111 {
1112  // TODO can't check if valid for this camera
1114  return 0;
1115 }
static int luaCB_set_file_attributes ( lua_State L)
static

Definiert in Zeile 2343 der Datei luascript.c.

2343  {
2345  return 1;
2346 }
static int luaCB_set_focus ( lua_State L)
static

Definiert in Zeile 871 der Datei luascript.c.

872 {
873  int sd = luaL_checknumber( L, 1 );
874  // if sd override not available now, fail immediately without calling set_focus
875  // to avoid unexpected results with SET_LATER
876  if(!shooting_can_focus())
877  {
878  lua_pushboolean(L, 0);
879  return 1;
880  }
881  // NOTE duplicated in modules/luascript.c and lib/ubasic/ubasic.c
882  // in AF lock or MF (canon or set by MF functions), set focus now
885  || camera_info.state.mode_video) // TODO video needs to be investigated, carried over from old code
886  {
888  }
889  else
890  {
891  // in an AF mode, set later
893  }
894  lua_pushboolean(L, 1);
895  return 1;
896 }
static int luaCB_set_focus_interlock_bypass ( lua_State L)
static

Definiert in Zeile 865 der Datei luascript.c.

866 {
868  return 0;
869 }
static int luaCB_set_iso_mode ( lua_State L)
static

Definiert in Zeile 898 der Datei luascript.c.

899 {
901  return 0;
902 }
static int luaCB_set_iso_real ( lua_State L)
static

Definiert in Zeile 904 der Datei luascript.c.

905 {
907  return 0;
908 }
static int luaCB_set_lcd_display ( lua_State L)
static

Definiert in Zeile 1856 der Datei luascript.c.

1857 {
1858  int val = on_off_value_from_lua_arg(L,1);
1859 
1860  if (val > 0) TurnOnDisplay();
1861  else TurnOffDisplay();
1862  return 0;
1863 }
static int luaCB_set_led ( lua_State L)
static

Definiert in Zeile 910 der Datei luascript.c.

911 {
912  int to, to1, to2;
913  to = luaL_checknumber( L, 1 );
914  to1 = luaL_checknumber( L, 2 );
915  to2 = 200;
916  if( lua_isnumber( L, 3 ) )
917  to2 = lua_tonumber( L, 3 );
918  camera_set_led(to, to1, to2);
919  return 0;
920 }
static int luaCB_set_levent_active ( lua_State L)
static

Definiert in Zeile 2006 der Datei luascript.c.

2007 {
2008  unsigned event_id;
2009  unsigned state;
2010 
2011  event_id = levent_id_from_lua_arg(L,1);
2012  state = on_off_value_from_lua_arg(L,2);
2013  SetLogicalEventActive(event_id,state);
2014  return 0;
2015 }
static int luaCB_set_levent_script_mode ( lua_State L)
static

Definiert in Zeile 2022 der Datei luascript.c.

2023 {
2025  return 0;
2026 }
static int luaCB_set_mf ( lua_State L)
static

Definiert in Zeile 424 der Datei luascript.c.

425 {
426  int val = on_off_value_from_lua_arg(L, 1);
427  if (val>0) val=DoMFLock(); // 1: enable
428  else val=UnlockMF(); // 0: disable
429  lua_pushnumber(L, val);
430  return 1;
431 }
static int luaCB_set_movie_status ( lua_State L)
static

Definiert in Zeile 1445 der Datei luascript.c.

1446 {
1448  return 0;
1449 }
static int luaCB_set_nd_filter ( lua_State L)
static

Definiert in Zeile 922 der Datei luascript.c.

923 {
925  return 0;
926 }
static int luaCB_set_prop ( lua_State L)
static

Definiert in Zeile 932 der Datei luascript.c.

933 {
935  return 0;
936 }
static int luaCB_set_prop_str ( lua_State L)
static

Definiert in Zeile 944 der Datei luascript.c.

944  {
945  int prop_id;
946  unsigned len;
947  const char *str;
948  prop_id = luaL_checknumber( L, 1 );
949  str = luaL_checklstring( L, 2, &len );
950  if(str && len > 0) {
951  lua_pushboolean( L, (set_property_case(prop_id,(void *)str,len) == 0));
952  } else {
953  return luaL_error( L, "invalid value");
954  }
955  return 1;
956 }
static int luaCB_set_raw ( lua_State L)
static

Definiert in Zeile 970 der Datei luascript.c.

971 {
973  return 0;
974 }
static int luaCB_set_raw_develop ( lua_State L)
static

Definiert in Zeile 1813 der Datei luascript.c.

1814 {
1816  return 0;
1817 }
static int luaCB_set_raw_nr ( lua_State L)
static

Definiert in Zeile 958 der Datei luascript.c.

959 {
960  conf.raw_nr = luaL_checknumber( L, 1 );
961  return 0;
962 }
static int luaCB_set_record ( lua_State L)
static

Definiert in Zeile 2078 der Datei luascript.c.

2079 {
2081  return 0;
2082 }
static int luaCB_set_remote_timing ( lua_State L)
static

Definiert in Zeile 1371 der Datei luascript.c.

1372 {
1373  int val= on_off_value_from_lua_arg(L,1);
1374  if (val > 0 )
1376  else
1378  return 1;
1379 }
static int luaCB_set_sv96 ( lua_State L)
static

Definiert in Zeile 982 der Datei luascript.c.

983 {
985  return 0;
986 }
static int luaCB_set_tv96 ( lua_State L)
static

Definiert in Zeile 994 der Datei luascript.c.

995 {
997  return 0;
998 }
static int luaCB_set_tv96_direct ( lua_State L)
static

Definiert in Zeile 988 der Datei luascript.c.

989 {
991  return 0;
992 }
static int luaCB_set_usb_capture_timeout ( lua_State L)
static

Definiert in Zeile 2604 der Datei luascript.c.

2605 {
2607  return 0;
2608 }
static int luaCB_set_user_av96 ( lua_State L)
static

Definiert in Zeile 1012 der Datei luascript.c.

1013 {
1015  return 0;
1016 }
static int luaCB_set_user_av_by_id ( lua_State L)
static

Definiert in Zeile 1006 der Datei luascript.c.

1007 {
1009  return 0;
1010 }
static int luaCB_set_user_av_by_id_rel ( lua_State L)
static

Definiert in Zeile 1000 der Datei luascript.c.

1001 {
1003  return 0;
1004 }
static int luaCB_set_user_tv96 ( lua_State L)
static

Definiert in Zeile 1030 der Datei luascript.c.

1031 {
1033  return 0;
1034 }
static int luaCB_set_user_tv_by_id ( lua_State L)
static

Definiert in Zeile 1024 der Datei luascript.c.

1025 {
1027  return 0;
1028 }
static int luaCB_set_user_tv_by_id_rel ( lua_State L)
static

Definiert in Zeile 1018 der Datei luascript.c.

1019 {
1021  return 0;
1022 }
static int luaCB_set_yield ( lua_State L)
static

Definiert in Zeile 2542 der Datei luascript.c.

static int luaCB_set_zoom ( lua_State L)
static

Definiert in Zeile 1048 der Datei luascript.c.

1049 {
1051  return 0;
1052 }
static int luaCB_set_zoom_rel ( lua_State L)
static

Definiert in Zeile 1042 der Datei luascript.c.

1043 {
1045  return 0;
1046 }
static int luaCB_set_zoom_speed ( lua_State L)
static

Definiert in Zeile 1036 der Datei luascript.c.

1037 {
1039  return 0;
1040 }
static int luaCB_shoot ( lua_State L)
static

Definiert in Zeile 439 der Datei luascript.c.

440 {
441  action_push_shoot(luaL_optnumber( L, 1, 1 ));
442  return lua_yield( L, 0 );
443 }
static int luaCB_shoot_hook_continue ( lua_State L)
static

Definiert in Zeile 2709 der Datei luascript.c.

2710 {
2711  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2713  return 0;
2714 }
static int luaCB_shoot_hook_count ( lua_State L)
static

Definiert in Zeile 2721 der Datei luascript.c.

2722 {
2723  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2725  return 1;
2726 }
static int luaCB_shoot_hook_is_ready ( lua_State L)
static

Definiert in Zeile 2698 der Datei luascript.c.

2699 {
2700  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2702  return 1;
2703 }
static int luaCB_shoot_hook_set ( lua_State L)
static

Definiert in Zeile 2687 der Datei luascript.c.

2688 {
2689  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2691  return 0;
2692 }
static int luaCB_shot_histo_enable ( lua_State L)
static

Definiert in Zeile 1570 der Datei luascript.c.

1571 {
1573  return 0;
1574 }
static int luaCB_shot_histo_write_to_file ( lua_State L)
static

Definiert in Zeile 1576 der Datei luascript.c.

1577 {
1579  return 0;
1580 }
static int luaCB_shut_down ( lua_State L)
static

Definiert in Zeile 1422 der Datei luascript.c.

1423 {
1424  if ( luaL_optnumber(L,1,0) == 1 )
1425  {
1426  shutdown();
1427  } else {
1429  }
1430  return 0;
1431 }
static int luaCB_sleep ( lua_State L)
static

Definiert in Zeile 468 der Datei luascript.c.

469 {
470  int delay = sleep_delay(luaL_checknumber( L, 1 ));
471 
472  if (delay > 0)
473  {
474  action_push(delay);
476  }
477 
478  return lua_yield( L, 0 );
479 }
static int luaCB_sv96_market_to_real ( lua_State L)
static

Definiert in Zeile 2643 der Datei luascript.c.

2644 {
2646  return 1;
2647 }
static int luaCB_sv96_real_to_market ( lua_State L)
static

Definiert in Zeile 2637 der Datei luascript.c.

2638 {
2640  return 1;
2641 }
static int luaCB_sv96_to_iso ( lua_State L)
static

Definiert in Zeile 2619 der Datei luascript.c.

2620 {
2622  return 1;
2623 }
static int luaCB_swap_partitions ( lua_State L)
static

Definiert in Zeile 527 der Datei luascript.c.

528 {
530  {
531  int partNr;
532 
533  if( lua_gettop(L)==1 )
534  {
535  partNr = luaL_checknumber(L, 1);
536  }
537  else
538  {
539  int partCount = get_part_count();
540  partNr = get_active_partition()+1;
541  if( partNr > partCount ) partNr = 1;
542  }
543  lua_pushboolean(L, swap_partitions(partNr));
544  return 1;
545  }
546  return 0;
547 }
static int luaCB_switch_mode_usb ( lua_State L)
static

Definiert in Zeile 2086 der Datei luascript.c.

2087 {
2089  return 0;
2090 }
static int luaCB_textbox ( lua_State L)
static

Definiert in Zeile 1223 der Datei luascript.c.

1223  {
1224  // Disconnect button input from script so buttons will work in the textbox
1226  // Switch to textbox gui mode. Text box prompt should be passed as param.
1227  int rv = libtextbox->textbox_init((int)luaL_optstring( L, 1, "Text box" ), //title
1228  (int)luaL_optstring( L, 2, "Enter text" ), //message
1229  luaL_optstring( L, 3, "" ), //default string
1230  luaL_optnumber( L, 4, 30), //max size of a text
1232  if (rv)
1233  {
1234  // Push textbox action onto stack - will loop doing nothing until textbox exits
1236  }
1237  else
1239 
1240  // Yield the script so that the action stack will process the AS_TEXTBOX action
1241  return lua_yield(L, 0);
1242 }
static int luaCB_tv96_to_usec ( lua_State L)
static

Definiert in Zeile 2667 der Datei luascript.c.

2668 {
2669  lua_pushnumber(L, (int)(shooting_get_shutter_speed_from_tv96(luaL_checknumber(L, 1)) * 1000000.0 + 0.5));
2670  return 1;
2671 }
static int luaCB_usb_force_active ( lua_State L)
static

Definiert in Zeile 1382 der Datei luascript.c.

1383 {
1385  return 1;
1386 }
static int luaCB_usb_sync_wait ( lua_State L)
static

Definiert in Zeile 1389 der Datei luascript.c.

1390 {
1392  return 0;
1393 }
static int luaCB_usec_to_tv96 ( lua_State L)
static

Definiert in Zeile 2661 der Datei luascript.c.

2662 {
2664  return 1;
2665 }
static int luaCB_wait_click ( lua_State L)
static

Definiert in Zeile 1073 der Datei luascript.c.

1074 {
1075  int delay = luaL_optnumber( L, 1, 0 );
1076  if (delay == 0) delay = -1;
1077  delay = sleep_delay(delay);
1078 
1079  // Reset 'clicked' key if it has not changed since last time
1081  {
1083  }
1084 
1085  // Set up for wait or click testing
1086  action_push(delay);
1088 
1089  // Check for short delay or key already pressed by calling action stack routine once now
1090  if (action_stack_AS_LUA_WAIT_CLICK() == 0)
1091  {
1092  return lua_yield( L, 0 );
1093  }
1094 
1095  return 0;
1096 }
static int luaCB_wheel_left ( lua_State L)
static

Definiert in Zeile 1123 der Datei luascript.c.

1124 {
1125  JogDial_CCW();
1126  return 0;
1127 }
static int luaCB_wheel_right ( lua_State L)
static

Definiert in Zeile 1117 der Datei luascript.c.

1118 {
1119  JogDial_CW();
1120  return 0;
1121 }
static int luaCB_write_usb_msg ( lua_State L)
static

Definiert in Zeile 2417 der Datei luascript.c.

2418 {
2419  ptp_script_msg *msg;
2420  int timeout = sleep_delay(luaL_optnumber(L,2,0));
2421  // TODO would it be better to either ignore this or return nil ?
2422  // a write_usb_msg(function_which_returns_no_value()) is an error in this case
2423  // replacing with nil might be more luaish
2424  if (lua_gettop(L) < 1)
2425  {
2426  return luaL_error(L,"missing argument");
2427  }
2429  // for user messages, trying to create a message from an incompatible type throws an error
2430  if (msg->subtype == PTP_CHDK_TYPE_UNSUPPORTED)
2431  {
2432  free(msg);
2433  return luaL_error(L,"unsupported type");
2434  }
2435  if (!msg)
2436  {
2437  return luaL_error(L,"failed to create message");
2438  }
2439  if (timeout)
2440  {
2441  action_push(timeout);
2442  action_push((int)msg);
2444  return lua_yield( L, 0 );
2445  }
2447  return 1;
2448 }
static unsigned on_off_value_from_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 372 der Datei luascript.c.

373 {
374  if( lua_isboolean(L,index) ) {
375  return lua_toboolean(L,index);
376  }
377  else {
378  return luaL_checknumber(L,index);
379  }
380 }
static int pack_native_args ( lua_State L,
unsigned  start,
unsigned *  argbuf 
)
static

Definiert in Zeile 2097 der Datei luascript.c.

2098 {
2099  unsigned i;
2100  unsigned end = lua_gettop(L);
2101 
2102  for(i = start; i <= end; i++,argbuf++) {
2103  if (lua_type(L, i) == LUA_TSTRING) {
2104  *argbuf=(unsigned)lua_tostring( L, i);
2105  }
2106  else if (lua_type(L, i) == LUA_TNUMBER) {
2107  *argbuf=lua_tonumber( L, i);
2108  }
2109  else {
2110  return 0;
2111  }
2112  }
2113  return 1;
2114 }
void register_lua_funcs ( lua_State L)

Definiert in Zeile 2972 der Datei luascript.c.

2973 {
2974  const luaL_reg *r;
2975 
2976  register_shoot_hooks( L );
2977  luaopen_rawop( L );
2978 
2981  lua_setglobal( L, "click" );
2982 
2985  lua_setglobal( L, "press" );
2986 
2989  lua_setglobal( L, "release" );
2990 
2991  for(r=chdk_funcs;r->name;r++) {
2992  lua_pushcfunction( L, r->func );
2993  lua_setglobal( L, r->name );
2994  }
2995  luaL_dostring(L,"function usb_msg_table_to_string(t)"
2996  " local v2s=function(v)"
2997  " local t=type(v)"
2998  " if t=='string' then return v end"
2999  " if t=='number' or t=='boolean' or t=='nil' then return tostring(v) end"
3000  " return '' end"
3001  " local r=''"
3002  " for k,v in pairs(t) do"
3003  " local s,vs=''"
3004  " if type(v)=='table' then"
3005  " for i=1,table.maxn(v) do"
3006  " s=s..'\\t'..v2s(v[i]) end"
3007  " else"
3008  " vs=v2s(v)"
3009  " if #vs then s=s..'\\t'..vs end"
3010  " end"
3011  " vs=v2s(k)"
3012  " if #vs>0 and #s>0 then r=r..vs..s..'\\n' end"
3013  " end"
3014  " return r"
3015  " end");
3016 
3017 }
void register_shoot_hook_fn ( lua_State L,
int  hook,
void *  hook_fn,
const char *  name 
)

Definiert in Zeile 2951 der Datei luascript.c.

2952 {
2953  lua_pushnumber( L, hook );
2954  lua_pushcclosure( L, hook_fn, 1 );
2955  lua_setfield( L, -2, name);
2956 }
void register_shoot_hooks ( lua_State L)

Definiert in Zeile 2958 der Datei luascript.c.

2959 {
2960  int i;
2961  for(i=0; i<SCRIPT_NUM_SHOOT_HOOKS;i++) {
2962  lua_createtable(L, 0, 4);
2964 // register_shoot_hook_fn(L,i,luaCB_shoot_hook_wait_ready,"wait_ready");
2969  }
2970 }
static void return_string_selected ( const char *  str)
static

Definiert in Zeile 1190 der Datei luascript.c.

1190  {
1191  // Reconnect button input to script - will also signal action stack
1192  // that file browser / textbox is finished and return last selected file
1193  // to script caller
1195 
1196  // Push selected file as script return value
1197  lua_pushstring( Lt, (str && str[0])? str : NULL );
1198 }
static void set_meminfo_num ( lua_State L,
const char *  name,
int  val 
)
static

Definiert in Zeile 2451 der Datei luascript.c.

2451  {
2452  if(val != -1) {
2453  set_number_field( L, name, val );
2454  }
2455 }
void set_number_field ( lua_State L,
const char *  key,
int  val 
)

Definiert in Zeile 1783 der Datei luascript.c.

1784 {
1785  lua_pushnumber(L, val);
1786  lua_setfield(L, -2, key);
1787 }
void set_string_field ( lua_State L,
const char *  key,
const char *  val 
)

Definiert in Zeile 1777 der Datei luascript.c.

1778 {
1779  lua_pushstring(L, val);
1780  lua_setfield(L, -2, key);
1781 }
static int sleep_delay ( int  delay)
static

Definiert in Zeile 456 der Datei luascript.c.

457 {
458  /* delay of -1 signals indefinite (actually 1 day) delay */
459  if (delay == -1)
460  delay = 86400000;
461 
462  if (delay > 0)
463  return delay + get_tick_count();
464 
465  return 0;
466 }

Variablen-Dokumentation

const luaL_Reg chdk_funcs[]
static

Definiert in Zeile 2731 der Datei luascript.c.

Definiert in Zeile 76 der Datei luascript.c.

lua_State* Lt

Definiert in Zeile 77 der Datei luascript.c.

int lua_script_is_ptp
static

Definiert in Zeile 81 der Datei luascript.c.

int ptp_saved_alt_state
static

Definiert in Zeile 82 der Datei luascript.c.

int run_first_resume
static

Definiert in Zeile 83 der Datei luascript.c.

int run_hook_count
static

Definiert in Zeile 85 der Datei luascript.c.

int run_start_tick
static

Definiert in Zeile 84 der Datei luascript.c.

int yield_hook_enabled
static

Definiert in Zeile 91 der Datei luascript.c.

unsigned yield_max_count
static

Definiert in Zeile 89 der Datei luascript.c.

unsigned yield_max_ms
static

Definiert in Zeile 90 der Datei luascript.c.