CHDK_DE Vorschauversion  Trunk Rev. 5575
 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_canon_image_format (lua_State *L)
 
static int luaCB_get_canon_raw_support (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_canon_image_format (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_set_clock (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 luaCB_force_analog_av (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 2791 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 1078 der Datei luascript.c.

1079 {
1080  // Check key pressed or timeout
1082  {
1083  // If timed out set key state to "no_key", otherwise key pressed so set last checked time
1086  else
1088 
1089  action_pop_func(1);
1090  return 1;
1091  }
1092 
1093  return 0;
1094 }
static int action_stack_AS_SCRIPT_READ_USB_MSG ( )
static

Definiert in Zeile 2409 der Datei luascript.c.

2410 {
2412 
2413  if ((get_tick_count() >= action_top(2)) || msg)
2414  {
2415  if (msg && msg->data)
2416  {
2417  lua_pushlstring(Lt,msg->data,msg->size);
2418  }
2419  else
2420  {
2421  lua_pushnil(Lt);
2422  }
2423  action_pop_func(1);
2424  return 1;
2425  }
2426  return 0;
2427 }
static int action_stack_AS_SCRIPT_WRITE_USB_MSG ( )
static

Definiert in Zeile 2429 der Datei luascript.c.

2430 {
2432 
2433  int r = ptp_script_write_msg(msg);
2434 
2435  if ((get_tick_count() >= action_top(3)) || r)
2436  {
2437  lua_pushboolean(Lt,r);
2438  action_pop_func(2);
2439  return 1;
2440  }
2441  return 0;
2442 }
static int action_stack_AS_WAIT_MODULE ( )
static

Definiert in Zeile 1223 der Datei luascript.c.

1224 {
1225  // state_kbd_script_run is set to 0 when the file browser is started from a Lua script
1226  // it is reset back to 1 when the file browser exits and control is returned back to
1227  // the script
1229  {
1230  action_pop_func(0);
1231  }
1232  return 0;
1233 }
static unsigned levent_id_from_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 1925 der Datei luascript.c.

1926 {
1927  unsigned event_id;
1928  if (lua_type(L, index) == LUA_TSTRING) {
1929  const char *ev_name = lua_tostring(L, index);
1930  event_id = levent_id_for_name(ev_name);
1931  if (event_id == 0) {
1932  return luaL_error( L, "bad event name '%s'", ev_name );
1933  }
1934  }
1935  // could check here if it is in the table, but even valid ones can crash
1936  // so we avoid searching the table if given a number
1937  else if (lua_type(L,index) == LUA_TNUMBER){
1938  event_id = lua_tonumber(L,index);
1939  }
1940  else {
1941  return luaL_error( L, "expected event name or id" );
1942  }
1943  return event_id;
1944 }
static unsigned levent_index_from_id_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 1950 der Datei luascript.c.

1951 {
1952  if (lua_type(L, index) == LUA_TSTRING) {
1953  return levent_index_for_name(lua_tostring(L, index));
1954  }
1955  else if (lua_type(L,index) == LUA_TNUMBER){
1956  return levent_index_for_id(lua_tonumber(L,index));
1957  }
1958  else {
1959  return luaL_error( L, "expected string or number" );
1960  }
1961 }
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 3117 der Datei luascript.c.

3117 { 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 3092 der Datei luascript.c.

3093 {
3094  lua_pushstring( L, name );
3095  if (isTable)
3096  {
3097  lua_createtable(L, labelCount, 2);
3098  int i;
3099  for (i=0; i<labelCount; i++)
3100  {
3101  lua_pushstring(L,labels[i]);
3102  lua_rawseti(L,-2,i+1);
3103  }
3104  SET_INT_FIELD("index", value+1); // Make value 1 based for Lua table index
3105  SET_STR_FIELD("value", labels[value]);
3106  }
3107  else
3108  {
3109  if (isBool)
3110  lua_pushboolean( L, value );
3111  else
3112  lua_pushnumber( L, value );
3113  }
3115 }
static int luaCB_aperture_to_av96 ( lua_State L)
static

Definiert in Zeile 2710 der Datei luascript.c.

2711 {
2713  return 1;
2714 }
static int luaCB_autostarted ( lua_State L)
static

Definiert in Zeile 1366 der Datei luascript.c.

1367 {
1369  return 1;
1370 }
static int luaCB_av96_to_aperture ( lua_State L)
static

Definiert in Zeile 2716 der Datei luascript.c.

2717 {
2719  return 1;
2720 }
static int luaCB_bitand ( lua_State L)
static

Definiert in Zeile 1766 der Datei luascript.c.

1767 {
1768  int v1 = (luaL_checknumber(L,1));
1769  int v2 = (luaL_checknumber(L,2));
1770  lua_pushnumber( L, v1 & v2 );
1771  return 1;
1772 }
static int luaCB_bitnot ( lua_State L)
static

Definiert in Zeile 1814 der Datei luascript.c.

1815 {
1816  unsigned val = (luaL_checknumber(L,1));
1817  lua_pushnumber( L, ~val );
1818  return 1;
1819 }
static int luaCB_bitor ( lua_State L)
static

Definiert in Zeile 1774 der Datei luascript.c.

1775 {
1776  int v1 = (luaL_checknumber(L,1));
1777  int v2 = (luaL_checknumber(L,2));
1778  lua_pushnumber( L, v1 | v2 );
1779  return 1;
1780 }
static int luaCB_bitshl ( lua_State L)
static

Definiert in Zeile 1790 der Datei luascript.c.

1791 {
1792  int val = (luaL_checknumber(L,1));
1793  unsigned shift = (luaL_checknumber(L,2));
1794  lua_pushnumber( L, val << shift );
1795  return 1;
1796 }
static int luaCB_bitshri ( lua_State L)
static

Definiert in Zeile 1798 der Datei luascript.c.

1799 {
1800  int val = (luaL_checknumber(L,1));
1801  unsigned shift = (luaL_checknumber(L,2));
1802  lua_pushnumber( L, val >> shift );
1803  return 1;
1804 }
static int luaCB_bitshru ( lua_State L)
static

Definiert in Zeile 1806 der Datei luascript.c.

1807 {
1808  unsigned val = (luaL_checknumber(L,1));
1809  unsigned shift = (luaL_checknumber(L,2));
1810  lua_pushnumber( L, val >> shift );
1811  return 1;
1812 }
static int luaCB_bitxor ( lua_State L)
static

Definiert in Zeile 1782 der Datei luascript.c.

1783 {
1784  int v1 = (luaL_checknumber(L,1));
1785  int v2 = (luaL_checknumber(L,2));
1786  lua_pushnumber( L, v1 ^ v2 );
1787  return 1;
1788 }
static int luaCB_call_event_proc ( lua_State L)
static

Definiert in Zeile 2252 der Datei luascript.c.

2253 {
2255  {
2256  const char *evpname;
2257  unsigned *argbuf;
2258  unsigned n_args = lua_gettop(L);
2259 
2260  evpname=luaL_checkstring( L, 1 );
2261 
2262  argbuf=malloc(n_args * 4);
2263  if (!argbuf)
2264  {
2265  return luaL_error( L, "malloc fail" );
2266  }
2267 
2268  // event proc name is first arg
2269  *argbuf = (unsigned)evpname;
2270 
2271  if(!pack_native_args(L,2,argbuf+1))
2272  {
2273  free(argbuf);
2274  return luaL_error( L, "expected string or number" );
2275  }
2276 
2278  free(argbuf);
2279  return 1;
2280  }
2281  return luaL_error( L, "native calls disabled" );
2282 }
static int luaCB_call_func_ptr ( lua_State L)
static

Definiert in Zeile 2198 der Datei luascript.c.

2199 {
2201  {
2202  unsigned *argbuf=NULL;
2203  unsigned n_args = lua_gettop(L)-1;
2204  void *fptr;
2205 
2206  fptr=(void *)luaL_checknumber( L, 1 );
2207 
2208  if (n_args)
2209  {
2210  argbuf=malloc(n_args * 4);
2211  if(!argbuf)
2212  {
2213  return luaL_error( L, "malloc fail" );
2214  }
2215  if(!pack_native_args(L, 2, argbuf))
2216  {
2217  free(argbuf);
2218  return luaL_error( L, "expected string or number" );
2219  }
2220  }
2221 
2222  lua_pushnumber( L, call_func_ptr(fptr, argbuf, n_args) );
2223  free(argbuf);
2224  return 1;
2225  }
2226  return luaL_error( L, "native calls disabled" );
2227 }
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 1347 der Datei luascript.c.

1347  {
1348  draw_restore();
1349  return 0;
1350 }
static int luaCB_draw_ellipse ( lua_State L)
static

Definiert in Zeile 1309 der Datei luascript.c.

1309  {
1310  coord x1=luaL_checknumber(L,1);
1311  coord y1=luaL_checknumber(L,2);
1312  coord a=luaL_checknumber(L,3);
1313  coord b=luaL_checknumber(L,4);
1315  draw_ellipse(x1,y1,a,b,cl,0);
1316  return 0;
1317 }
static int luaCB_draw_ellipse_filled ( lua_State L)
static

Definiert in Zeile 1319 der Datei luascript.c.

1319  {
1320  coord x1=luaL_checknumber(L,1);
1321  coord y1=luaL_checknumber(L,2);
1322  coord a=luaL_checknumber(L,3);
1323  coord b=luaL_checknumber(L,4);
1325  draw_ellipse(x1,y1,a,b,cl,DRAW_FILLED);
1326  return 0;
1327 }
static int luaCB_draw_line ( lua_State L)
static

Definiert in Zeile 1276 der Datei luascript.c.

1276  {
1277  coord x1=luaL_checknumber(L,1);
1278  coord y1=luaL_checknumber(L,2);
1279  coord x2=luaL_checknumber(L,3);
1280  coord y2=luaL_checknumber(L,4);
1282  draw_line(x1,y1,x2,y2,cl);
1283  return 0;
1284 }
static int luaCB_draw_pixel ( lua_State L)
static

Definiert in Zeile 1268 der Datei luascript.c.

1268  {
1269  coord x1=luaL_checknumber(L,1);
1270  coord y1=luaL_checknumber(L,2);
1272  draw_pixel(x1,y1,cl);
1273  return 0;
1274 }
static int luaCB_draw_rect ( 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 x2=luaL_checknumber(L,3);
1290  coord y2=luaL_checknumber(L,4);
1292  int th=luaL_optnumber(L,6,1) & RECT_BORDER_MASK;
1293  draw_rectangle(x1,y1,x2,y2,MAKE_COLOR(cl,cl),th);
1294  return 0;
1295 }
static int luaCB_draw_rect_filled ( lua_State L)
static

Definiert in Zeile 1297 der Datei luascript.c.

1297  {
1298  coord x1 =luaL_checknumber(L,1);
1299  coord y1 =luaL_checknumber(L,2);
1300  coord x2 =luaL_checknumber(L,3);
1301  coord y2 =luaL_checknumber(L,4);
1304  int th =luaL_optnumber(L,7,1) & RECT_BORDER_MASK;
1305  draw_rectangle(x1,y1,x2,y2,MAKE_COLOR(clb,clf),th|DRAW_FILLED);
1306  return 0;
1307 }
static int luaCB_draw_string ( lua_State L)
static

Definiert in Zeile 1329 der Datei luascript.c.

1330 {
1331  coord x1 = luaL_checknumber(L,1);
1332  coord y1 = luaL_checknumber(L,2);
1333  const char *t = luaL_checkstring( L, 3 );
1336  int xsize = luaL_optnumber(L,6,1);
1337  int ysize = luaL_optnumber(L,7,xsize);
1338 
1339  if ((xsize <= 1) && (ysize <= 1))
1340  draw_string(x1, y1, t, MAKE_COLOR(clb,clf));
1341  else
1342  draw_string_scaled(x1, y1, t, MAKE_COLOR(clb,clf), xsize, ysize);
1343 
1344  return 0;
1345 }
static int luaCB_enter_alt ( lua_State L)
static

Definiert in Zeile 1418 der Datei luascript.c.

1419 {
1420  enter_alt();
1421  // if alt explicitly changed by script, set as 'saved' state
1422  if(lua_script_is_ptp) {
1423  ptp_saved_alt_state = 1;
1424  }
1425  return 0;
1426 }
static int luaCB_exit_alt ( lua_State L)
static

Definiert in Zeile 1428 der Datei luascript.c.

1429 {
1430  exit_alt();
1431  // if alt explicitly changed by script, set as 'saved' state
1432  if(lua_script_is_ptp) {
1433  ptp_saved_alt_state = 0;
1434  }
1435  return 0;
1436 }
static int luaCB_file_browser ( lua_State L)
static

Definiert in Zeile 1235 der Datei luascript.c.

1235  {
1236  // Disconnect button input from script so buttons will work in file browser
1238  // Push file browser action onto stack - will loop doing nothing until file browser exits
1240  // Switch to file browser gui mode. Path can be supplied in call or defaults to "A" (root directory).
1242  // Yield the script so that the action stack will process the AS_FILE_BROWSER action
1243  return lua_yield(L, 0);
1244 }
static int luaCB_force_analog_av ( lua_State L)
static

Definiert in Zeile 2147 der Datei luascript.c.

2148 {
2150  return 1;
2151 }
static int luaCB_get_alt_mode ( lua_State L)
static

Definiert in Zeile 1438 der Datei luascript.c.

1439 {
1441  return 1 ;
1442 }
static int luaCB_get_autostart ( lua_State L)
static

Definiert in Zeile 1372 der Datei luascript.c.

1373 {
1375  return 1;
1376 }
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 1833 der Datei luascript.c.

1834 {
1835  lua_createtable(L, 0, 10);
1836  set_string_field( L,"platform", camera_info.platform );
1837  set_string_field( L,"platsub", camera_info.platformsub );
1838  set_string_field( L,"version", camera_info.chdk_ver );
1839  set_string_field( L,"build_number", camera_info.build_number );
1840  set_string_field( L,"build_revision", camera_info.build_svnrev );
1841  set_string_field( L,"build_date", camera_info.build_date );
1842  set_string_field( L,"build_time", camera_info.build_time );
1843  set_string_field( L,"os", camera_info.os );
1844  set_number_field( L,"platformid", conf.platformid );
1845  set_number_field( L,"digic", camera_info.cam_digic );
1846  return 1;
1847 }
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_canon_image_format ( lua_State L)
static

Definiert in Zeile 793 der Datei luascript.c.

794 {
796  return 1;
797 }
static int luaCB_get_canon_raw_support ( lua_State L)
static

Definiert in Zeile 800 der Datei luascript.c.

801 {
803  return 1;
804 }
static int luaCB_get_config_value ( lua_State L)
static

Definiert in Zeile 2295 der Datei luascript.c.

2295  {
2296  unsigned int argc = lua_gettop(L);
2297  unsigned int id, i;
2298  int ret = 1;
2299  tConfigVal configVal;
2300 
2301  if( argc>=1 ) {
2302  id = luaL_checknumber(L, 1);
2303  switch( conf_getValue(id, &configVal) ) {
2304  case CONF_VALUE:
2305  lua_pushnumber(L, configVal.numb);
2306  break;
2307  case CONF_INT_PTR:
2308  lua_createtable(L, 0, configVal.numb);
2309  for( i=0; i<configVal.numb; i++ ) {
2310  lua_pushinteger(L, configVal.pInt[i]);
2311  lua_rawseti(L, -2, i+1); //t[i+1]=configVal.pInt[i]
2312  }
2313  break;
2314  case CONF_CHAR_PTR:
2315  lua_pushstring(L, configVal.str);
2316  break;
2317  case CONF_OSD_POS:
2318  lua_pushnumber(L, configVal.pos.x);
2319  lua_pushnumber(L, configVal.pos.y); ret++;
2320  break;
2321  default:
2322  if( argc>=2) { //Default
2323  ret = argc-1;
2324  } else {
2325  lua_pushnil(L);
2326  }
2327  break;
2328  }
2329  } else {
2330  lua_pushnil(L);
2331  }
2332  return ret;
2333 }
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 1918 der Datei luascript.c.

1919 {
1921  return 1;
1922 }
static int luaCB_get_drive_mode ( lua_State L)
static

Definiert in Zeile 1486 der Datei luascript.c.

1487 {
1489  return 1;
1490 }
static int luaCB_get_ev ( lua_State L)
static

Definiert in Zeile 1570 der Datei luascript.c.

1571 {
1573  return 1;
1574 }
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 1510 der Datei luascript.c.

1511 {
1513  return 1;
1514 }
static int luaCB_get_flash_params_count ( lua_State L)
static

Definiert in Zeile 861 der Datei luascript.c.

862 {
864  return 1;
865 }
static int luaCB_get_flash_ready ( lua_State L)
static

Definiert in Zeile 1522 der Datei luascript.c.

1523 {
1525  return 1;
1526 }
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 1492 der Datei luascript.c.

1493 {
1495  return 1;
1496 }
static int luaCB_get_focus_ok ( lua_State L)
static

Definiert in Zeile 1504 der Datei luascript.c.

1505 {
1507  return 1;
1508 }
static int luaCB_get_focus_state ( lua_State L)
static

Definiert in Zeile 1498 der Datei luascript.c.

1499 {
1501  return 1;
1502 }
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 1360 der Datei luascript.c.

1361 {
1363  return 1;
1364 }
static int luaCB_get_gui_screen_width ( lua_State L)
static

Definiert in Zeile 1354 der Datei luascript.c.

1355 {
1357  return 1;
1358 }
static int luaCB_get_histo_range ( lua_State L)
static

Definiert in Zeile 1585 der Datei luascript.c.

1586 {
1587  int from = (luaL_checknumber(L,1));
1588  int to = (luaL_checknumber(L,2));
1590  return 1;
1591 }
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 1528 der Datei luascript.c.

1529 {
1531  return 1;
1532 }
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 1968 der Datei luascript.c.

1969 {
1970  unsigned event_index = levent_index_from_id_lua_arg(L,1);
1971  if (event_index == LEVENT_INVALID_INDEX) {
1972  lua_pushnil(L);
1973  return 1;
1974  }
1975  lua_pushstring(L, levent_table[event_index].name);
1976  lua_pushnumber(L, levent_table[event_index].id);
1977  lua_pushnumber(L, levent_table[event_index].param);
1978  return 3;
1979 }
static int luaCB_get_levent_def_by_index ( lua_State L)
static

Definiert in Zeile 2003 der Datei luascript.c.

2004 {
2005  unsigned i = luaL_checknumber(L,1);
2006  if(i >= levent_count()) {
2007  lua_pushnil(L);
2008  return 1;
2009  }
2010  lua_pushstring(L, levent_table[i].name);
2011  lua_pushnumber(L, levent_table[i].id);
2012  lua_pushnumber(L, levent_table[i].param);
2013  return 3;
2014 }
static int luaCB_get_levent_index ( lua_State L)
static

Definiert in Zeile 1986 der Datei luascript.c.

1987 {
1988  unsigned event_index = levent_index_from_id_lua_arg(L,1);
1989  if (event_index == LEVENT_INVALID_INDEX) {
1990  lua_pushnil(L);
1991  }
1992  else {
1993  lua_pushnumber(L, event_index);
1994  }
1995  return 1;
1996 }
static int luaCB_get_live_histo ( lua_State L)
static

Definiert in Zeile 1611 der Datei luascript.c.

1612 {
1613  unsigned short *h = malloc(256*sizeof(short));
1614  if(!h) {
1615  return luaL_error(L,"malloc fail");
1616  }
1617  int total=live_histogram_read_y(h);
1618  lua_createtable(L, 0, 256);
1619  int i;
1620  for(i=0;i<256;i++) {
1621  lua_pushnumber(L,h[i]);
1622  lua_rawseti(L,-2,i);
1623  }
1624  free(h);
1625  lua_pushnumber(L,total);
1626  return 2;
1627 }
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 2545 der Datei luascript.c.

2545  {
2546  const char *heapname = luaL_optstring( L, 1, "combined" );
2547  cam_meminfo meminfo;
2548  if (strcmp(heapname,"combined") == 0) {
2549  GetCombinedMemInfo(&meminfo);
2550  meminfo.start_address=meminfo.end_address=-1; // not meaningful
2551  }
2552  else if (strcmp(heapname,"system") == 0)
2553  {
2554  GetMemInfo(&meminfo);
2555  }
2556  else if ((strcmp(heapname,"aram") == 0))
2557  {
2558  if(!GetARamInfo(&meminfo)) {
2559  lua_pushboolean(L,0);
2560  return 1;
2561  }
2562  }
2563  else if (strcmp(heapname,"exmem") == 0)
2564  {
2565  if(!GetExMemInfo(&meminfo)) {;
2566  lua_pushboolean(L,0);
2567  return 1;
2568  }
2569  }
2570  else
2571  {
2572  lua_pushboolean(L,0);
2573  return 1;
2574  }
2575  // adjust start and size, if CHDK is loaded at heap start
2576  if(meminfo.start_address == camera_info.text_start) {
2578  meminfo.total_size -= camera_info.memisosize;
2579  }
2580  lua_createtable(L, 0, 13); // might not always use 13, but doesn't hurt
2581  set_string_field( L,"name", heapname );
2582  // CHDK allocates from all available heaps now
2583  lua_pushboolean( L, 1);
2584  lua_setfield(L, -2, "chdk_malloc");
2585  set_number_field( L, "chdk_start", camera_info.text_start);
2586  set_number_field( L, "chdk_size", camera_info.memisosize );
2587  set_meminfo_num( L, "start_address", meminfo.start_address );
2588  set_meminfo_num( L, "end_address", meminfo.end_address);
2589  set_meminfo_num( L, "total_size", meminfo.total_size);
2590  set_meminfo_num( L, "allocated_size", meminfo.allocated_size);
2591  set_meminfo_num( L, "allocated_peak", meminfo.allocated_peak);
2592  set_meminfo_num( L, "allocated_count", meminfo.allocated_count);
2593  set_meminfo_num( L, "free_size", meminfo.free_size);
2594  set_meminfo_num( L, "free_block_max_size", meminfo.free_block_max_size);
2595  set_meminfo_num( L, "free_block_count", meminfo.free_block_count);
2596  return 1;
2597 }
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 1849 der Datei luascript.c.

1850 {
1854  return 3;
1855 }
static int luaCB_get_movie_status ( lua_State L)
static

Definiert in Zeile 1462 der Datei luascript.c.

1463 {
1465  return 1;
1466 }
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 1546 der Datei luascript.c.

1547 {
1548  int to;
1549  if (camera_info.cam_has_nd_filter == 0)
1550  {
1551  to = 0;
1552  }
1553  else
1554  {
1556  to = 1;
1557  else
1558  to = 2;
1559  }
1560  lua_pushnumber( L, to );
1561  return 1;
1562 }
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 1534 der Datei luascript.c.

1535 {
1537  return 1;
1538 }
static int luaCB_get_parameter_data ( lua_State L)
static

Definiert in Zeile 830 der Datei luascript.c.

831 {
832  unsigned size;
833  unsigned id = luaL_checknumber( L, 1 );
834  unsigned val;
835 
836  size = get_parameter_size(id);
837  if (size == 0) {
838  // return nil
839  return 0;
840  }
841  if (size >= 1 && size <= 4) {
842  val = 0;
843  get_parameter_data( id, &val, size );
844  lua_pushlstring( L, (char *)&val, size );
845  // for convenience, params that fit in a number are returned in one as a second result
846  lua_pushnumber( L, val );
847  return 2;
848  }
849  else {
850  char *buf = malloc(size);
851  if(!buf) {
852  luaL_error( L, "malloc failed in luaCB_get_parameter_data" );
853  }
854  get_parameter_data( id, buf, size );
855  lua_pushlstring( L, buf, size );
856  free(buf);
857  return 1;
858  }
859 }
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 1564 der Datei luascript.c.

1565 {
1567  return 1;
1568 }
static int luaCB_get_raw ( lua_State L)
static

Definiert in Zeile 999 der Datei luascript.c.

1000 {
1002  return 1;
1003 }
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 987 der Datei luascript.c.

988 {
989  lua_pushnumber( L, conf.raw_nr );
990  return 1;
991 }
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 1516 der Datei luascript.c.

1517 {
1519  return 1;
1520 }
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 1635 der Datei luascript.c.

1636 {
1637  int which = (luaL_checknumber( L, 1 ));
1638  int temp = -100; // do something insane if users passes bad value
1639  switch (which)
1640  {
1641  case 0:
1642  temp = get_optical_temp();
1643  break;
1644  case 1:
1645  temp = get_ccd_temp();
1646  break;
1647  case 2:
1648  temp = get_battery_temp();
1649  break;
1650  }
1651  lua_pushnumber( L, temp );
1652  return 1;
1653 }
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 1655 der Datei luascript.c.

1656 {
1657  int r = -1;
1658  static struct tm *ttm;
1659  ttm = get_localtime();
1660  const char *t = luaL_checkstring( L, 1 );
1661  if (strncmp("s", t, 1)==0) r = ttm->tm_sec;
1662  else if (strncmp("m", t, 1)==0) r = ttm->tm_min;
1663  else if (strncmp("h", t, 1)==0) r = ttm->tm_hour;
1664  else if (strncmp("D", t, 1)==0) r = ttm->tm_mday;
1665  else if (strncmp("M", t, 1)==0) r = ttm->tm_mon+1;
1666  else if (strncmp("Y", t, 1)==0) r = 1900+ttm->tm_year;
1667  lua_pushnumber( L, r );
1668  return 1;
1669 }
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 2620 der Datei luascript.c.

2621 {
2623  return 1;
2624 }
static int luaCB_get_usb_capture_target ( lua_State L)
static

Definiert in Zeile 2647 der Datei luascript.c.

2648 {
2650  return 1;
2651 }
static int luaCB_get_usb_power ( lua_State L)
static

Definiert in Zeile 1387 der Datei luascript.c.

1388 {
1389  lua_pushnumber( L, get_usb_power(luaL_optnumber( L, 1, 0 )) );
1390  return 1;
1391 }
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 812 der Datei luascript.c.

813 {
815  return 1;
816 }
static int luaCB_get_user_tv_id ( lua_State L)
static

Definiert in Zeile 806 der Datei luascript.c.

807 {
809  return 1;
810 }
static int luaCB_get_vbatt ( lua_State L)
static

Definiert in Zeile 818 der Datei luascript.c.

819 {
821  return 1;
822 }
static int luaCB_get_video_button ( lua_State L)
static

Definiert in Zeile 1474 der Datei luascript.c.

1475 {
1477  return 1;
1478 }
static int luaCB_get_video_recording ( lua_State L)
static

Definiert in Zeile 1480 der Datei luascript.c.

1481 {
1483  return 1;
1484 }
static int luaCB_get_zoom ( lua_State L)
static

Definiert in Zeile 824 der Datei luascript.c.

825 {
827  return 1;
828 }
static int luaCB_get_zoom_steps ( lua_State L)
static

Definiert in Zeile 1540 der Datei luascript.c.

1541 {
1543  return 1;
1544 }
static int luaCB_init_usb_capture ( lua_State L)
static

Definiert in Zeile 2634 der Datei luascript.c.

2635 {
2636  int what=luaL_checknumber(L, 1);
2637  int startline=luaL_optnumber(L, 2, 0);
2638  int numlines=luaL_optnumber(L, 3, 0);
2639  lua_pushboolean(L,remotecap_set_target(what,startline,numlines));
2640  return 1;
2641 }
static int luaCB_is_capture_mode_valid ( lua_State L)
static

Definiert in Zeile 2105 der Datei luascript.c.

2106 {
2107  int modenum = luaL_checknumber(L,1);
2108  lua_pushboolean( L, shooting_mode_chdk2canon(modenum) != -1 );
2109  return 1;
2110 }
static int luaCB_is_key ( lua_State L)
static

Definiert in Zeile 1127 der Datei luascript.c.

1128 {
1130  return 1;
1131 }
static int luaCB_is_pressed ( lua_State L)
static

Definiert in Zeile 1121 der Datei luascript.c.

1122 {
1124  return 1;
1125 }
static int luaCB_iso_market_to_real ( lua_State L)
static

Definiert in Zeile 2692 der Datei luascript.c.

2693 {
2695  return 1;
2696 }
static int luaCB_iso_real_to_market ( lua_State L)
static

Definiert in Zeile 2686 der Datei luascript.c.

2687 {
2689  return 1;
2690 }
static int luaCB_iso_to_sv96 ( lua_State L)
static

Definiert in Zeile 2674 der Datei luascript.c.

2675 {
2677  return 1;
2678 }
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 2399 der Datei luascript.c.

2399  {
2401  return 1;
2402 }
static int luaCB_md_af_led_control ( lua_State L)
static

Definiert in Zeile 1152 der Datei luascript.c.

1153 {
1156  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
1157  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
1158  // clear previous values
1160  camera_info.perf.af_led.min = 0xFFFFFFFF;
1161  } else {
1162  camera_info.perf.md_af_tuning = 0; // Disable MD testing
1163  }
1164  return 0;
1165 }
static int luaCB_md_detect_motion ( lua_State L)
static

Definiert in Zeile 1180 der Datei luascript.c.

1181 {
1182  int columns = (luaL_optnumber(L,1,6));
1183  int rows = (luaL_optnumber(L,2,4));
1184  int pixel_measure_mode = (luaL_optnumber(L,3,1));
1185  int detection_timeout = (luaL_optnumber(L,4,10000));
1186  int measure_interval = (luaL_optnumber(L,5,7));
1187  int threshold = (luaL_optnumber(L,6,10));
1188  int draw_grid = (luaL_optnumber(L,7,1));
1189  // arg 8 is the return value in ubasic. We
1190  // ignore it here. - AUJ
1191  int clipping_region_mode = (luaL_optnumber(L,9,0));
1192  int clipping_region_column1 = (luaL_optnumber(L,10,0));
1193  int clipping_region_row1 = (luaL_optnumber(L,11,0));
1194  int clipping_region_column2 = (luaL_optnumber(L,12,0));
1195  int clipping_region_row2 = (luaL_optnumber(L,13,0));
1196  int parameters = (luaL_optnumber(L,14,1));
1197  int pixels_step = (luaL_optnumber(L,15,6));
1198  int msecs_before_trigger = (luaL_optnumber(L,16,0));
1199 
1201  columns, rows, pixel_measure_mode, detection_timeout,
1202  measure_interval, threshold, draw_grid,
1203  clipping_region_mode,
1204  clipping_region_column1, clipping_region_row1,
1205  clipping_region_column2, clipping_region_row2,
1206  parameters, pixels_step, msecs_before_trigger
1207  ))
1208  return lua_yield(L, 0);
1209  else
1210  return luaL_error( L, "md_init_motion_detector failed" );
1211 }
static int luaCB_md_get_cell_diff ( lua_State L)
static

Definiert in Zeile 1167 der Datei luascript.c.

1168 {
1170  return 1;
1171 }
static int luaCB_md_get_cell_val ( lua_State L)
static

Definiert in Zeile 1174 der Datei luascript.c.

1175 {
1177  return 1;
1178 }
static int luaCB_peek ( lua_State L)
static

Definiert in Zeile 1696 der Datei luascript.c.

1697 {
1698  unsigned addr = luaL_checknumber(L,1);
1699  unsigned size = luaL_optnumber(L, 2, 4);
1700  switch(size) {
1701  case 1:
1702  lua_pushnumber( L, *(unsigned char *)(addr) );
1703  break;
1704  case 2:
1705  if (addr & 0x1) {
1706  lua_pushnil(L);
1707  }
1708  else {
1709  lua_pushnumber( L, *(unsigned short *)(addr) );
1710  }
1711  break;
1712  case 4:
1713  if (addr & 0x3) {
1714  lua_pushnil(L);
1715  }
1716  else {
1717  lua_pushnumber( L, *(unsigned *)(addr) );
1718  }
1719  break;
1720  default:
1721  lua_pushnil(L);
1722 
1723  }
1724  return 1;
1725 }
static int luaCB_play_sound ( lua_State L)
static

Definiert in Zeile 1629 der Datei luascript.c.

1630 {
1631  play_sound(luaL_checknumber( L, 1 ));
1632  return 0;
1633 }
static int luaCB_poke ( lua_State L)
static

Definiert in Zeile 1733 der Datei luascript.c.

1734 {
1735  unsigned addr = luaL_checknumber(L,1);
1736  unsigned val = luaL_checknumber(L,2);
1737  unsigned size = luaL_optnumber(L, 3, 4);
1738  int status = 0;
1739  switch(size) {
1740  case 1:
1741  *(unsigned char *)(addr) = (unsigned char)val;
1742  status=1;
1743  break;
1744  case 2:
1745  if (!(addr & 0x1)) {
1746  *(unsigned short *)(addr) = (unsigned short)val;
1747  status=1;
1748  }
1749  break;
1750  case 4:
1751  if (!(addr & 0x3)) {
1752  *(unsigned *)(addr) = val;
1753  status=1;
1754  }
1755  break;
1756  }
1757  if(status) {
1758  lua_pushboolean(L,1);
1759  }
1760  else {
1761  lua_pushnil(L);
1762  }
1763  return 1;
1764 }
static int luaCB_post_levent_for_npt ( lua_State L)
static

Definiert in Zeile 2035 der Datei luascript.c.

2036 {
2037  unsigned event_id,arg;
2038 
2039  event_id = levent_id_from_lua_arg(L,1);
2040  arg = luaL_optnumber(L, 2, 0);
2041  PostLogicalEventForNotPowerType(event_id,arg);
2042  return 0;
2043 }
static int luaCB_post_levent_to_ui ( lua_State L)
static

Definiert in Zeile 2025 der Datei luascript.c.

2026 {
2027  unsigned event_id,arg;
2028 
2029  event_id = levent_id_from_lua_arg(L,1);
2030  arg = luaL_optnumber(L, 2, 0);
2031  PostLogicalEventToUI(event_id,arg);
2032  return 0;
2033 }
static int luaCB_print_screen ( lua_State L)
static

Definiert in Zeile 1456 der Datei luascript.c.

1457 {
1459  return 0;
1460 }
static int luaCB_raw_merge_add_file ( lua_State L)
static

Definiert in Zeile 1878 der Datei luascript.c.

1879 {
1881  return 1;
1882 }
static int luaCB_raw_merge_end ( lua_State L)
static

Definiert in Zeile 1884 der Datei luascript.c.

1885 {
1887  return 0;
1888 }
static int luaCB_raw_merge_start ( lua_State L)
static

Definiert in Zeile 1864 der Datei luascript.c.

1865 {
1866  int op = luaL_checknumber(L,1);
1867  if ((op == RAW_OPERATION_SUM || op == RAW_OPERATION_AVERAGE))
1868  {
1870  return 1;
1871  }
1872  else {
1873  return luaL_argerror(L,1,"invalid raw merge op");
1874  }
1875 }
static int luaCB_read_usb_msg ( lua_State L)
static

Definiert in Zeile 2450 der Datei luascript.c.

2451 {
2452  int timeout = sleep_delay(luaL_optnumber(L,1,0));
2453  if (timeout > 0)
2454  {
2455  action_push(timeout);
2457  return lua_yield( L, 0 );
2458  }
2460  if(msg)
2461  {
2462  lua_pushlstring(L,msg->data,msg->size);
2463  free(msg);
2464  return 1;
2465  }
2466  lua_pushnil(L);
2467  return 1;
2468 }
static int luaCB_reboot ( lua_State L)
static

Definiert in Zeile 2289 der Datei luascript.c.

2290 {
2291  lua_pushboolean(L, reboot(luaL_optstring( L, 1, NULL )));
2292  return 1;
2293 }
static int luaCB_save_config_file ( lua_State L)
static

Definiert in Zeile 2394 der Datei luascript.c.

2394  {
2396  return 1;
2397 }
static int luaCB_seconds_to_tv96 ( lua_State L)
static

Definiert in Zeile 2734 der Datei luascript.c.

2735 {
2737  return 1;
2738 }
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 1378 der Datei luascript.c.

1379 {
1380  int to;
1381  to = luaL_checknumber( L, 1 );
1382  if ( to >= 0 && to <= 3 ) conf.script_startup = to;
1383  conf_save();
1384  return 0;
1385 }
static int luaCB_set_av96 ( lua_State L)
static

Definiert in Zeile 873 der Datei luascript.c.

874 {
876  return 0;
877 }
static int luaCB_set_av96_direct ( lua_State L)
static

Definiert in Zeile 867 der Datei luascript.c.

868 {
870  return 0;
871 }
static int luaCB_set_backlight ( lua_State L)
static

Definiert in Zeile 1891 der Datei luascript.c.

1892 {
1893  int val = on_off_value_from_lua_arg(L,1);
1894 
1895  if (val > 0) TurnOnBackLight();
1896  else TurnOffBackLight();
1897  return 0;
1898 }
static int luaCB_set_canon_image_format ( lua_State L)
static

Definiert in Zeile 882 der Datei luascript.c.

883 {
885  return 1;
886 }
static int luaCB_set_capture_mode ( lua_State L)
static

Definiert in Zeile 2093 der Datei luascript.c.

2094 {
2095  int modenum = luaL_checknumber(L,1);
2096  lua_pushboolean( L, shooting_set_mode_chdk(modenum) );
2097  return 1;
2098 }
static int luaCB_set_capture_mode_canon ( lua_State L)
static

Definiert in Zeile 2078 der Datei luascript.c.

2079 {
2080  int modenum = luaL_checknumber(L,1);
2081  // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value
2082  if(modenum < 0)
2083  modenum &= 0xFFFF;
2085  return 1;
2086 }
static int luaCB_set_clock ( lua_State L)
static

Definiert in Zeile 1680 der Datei luascript.c.

1681 {
1682  set_clock(luaL_checknumber(L,1), // year, like 2020
1683  luaL_checknumber(L,2), // month, 1-12
1684  luaL_checknumber(L,3), // day, 1-31
1685  luaL_checknumber(L,4), // hour
1686  luaL_checknumber(L,5), // minute
1687  luaL_checknumber(L,6)); // second
1688  return 0;
1689 }
static int luaCB_set_config_autosave ( lua_State L)
static

Definiert in Zeile 2389 der Datei luascript.c.

2389  {
2391  return 0;
2392 }
static int luaCB_set_config_value ( lua_State L)
static

Definiert in Zeile 2335 der Datei luascript.c.

2335  {
2336  unsigned int argc = lua_gettop(L);
2337  unsigned int id, i, j;
2338  tConfigVal configVal = {0,0,0,0}; //initialize isXXX
2339 
2340  if( argc>=2 ) {
2341  id = luaL_checknumber(L, 1);
2342  for( i=2; i<=argc; i++) {
2343  switch( lua_type(L, i) ) {
2344  case LUA_TNUMBER:
2345  if( !configVal.isNumb ) {
2346  configVal.numb = luaL_checknumber(L, i);
2347  configVal.isNumb++;
2348  }
2349  switch( configVal.isPos ) {
2350  case 0: configVal.pos.x = luaL_checknumber(L, i); configVal.isPos++; break;
2351  case 1: configVal.pos.y = luaL_checknumber(L, i); configVal.isPos++; break;
2352  }
2353  break;
2354  case LUA_TSTRING:
2355  if( !configVal.isStr ) {
2356  configVal.str = (char*)luaL_checkstring(L, i);
2357  configVal.isStr++;
2358  }
2359  break;
2360  case LUA_TTABLE:
2361  if( !configVal.isPInt ) {
2362  configVal.numb = lua_objlen(L, i);
2363  if( configVal.pInt ) {
2364  free(configVal.pInt);
2365  configVal.pInt = NULL;
2366  }
2367  configVal.pInt = malloc(configVal.numb*sizeof(int));
2368  if( configVal.pInt ) {
2369  for( j=1; j<=configVal.numb; j++) {
2370  lua_rawgeti(L, i, j);
2371  configVal.pInt[j-1] = lua_tointeger(L, -1);
2372  lua_pop(L, 1);
2373  }
2374  }
2375  configVal.isPInt++;
2376  }
2377  break;
2378  }
2379  }
2380  lua_pushboolean(L, conf_setValue(id, configVal));
2381  if( configVal.pInt ) {
2382  free(configVal.pInt);
2383  configVal.pInt = NULL;
2384  }
2385  } else lua_pushboolean(L, 0);
2386  return 1;
2387 }
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 1911 der Datei luascript.c.

1912 {
1914  return 0;
1915 }
static int luaCB_set_ev ( lua_State L)
static

Definiert in Zeile 1576 der Datei luascript.c.

1577 {
1578  int to;
1579  to = luaL_checknumber( L, 1 );
1582  return 0;
1583 }
static int luaCB_set_exit_key ( lua_State L)
static

Definiert in Zeile 1133 der Datei luascript.c.

1134 {
1135  // TODO can't check if valid for this camera
1137  return 0;
1138 }
static int luaCB_set_file_attributes ( lua_State L)
static

Definiert in Zeile 2404 der Datei luascript.c.

2404  {
2406  return 1;
2407 }
static int luaCB_set_focus ( lua_State L)
static

Definiert in Zeile 894 der Datei luascript.c.

895 {
896  int sd = luaL_checknumber( L, 1 );
897  // if sd override not available now, fail immediately without calling set_focus
898  // to avoid unexpected results with SET_LATER
899  if(!shooting_can_focus())
900  {
901  lua_pushboolean(L, 0);
902  return 1;
903  }
904  // NOTE duplicated in modules/luascript.c and lib/ubasic/ubasic.c
905  // in AF lock or MF (canon or set by MF functions), set focus now
908  || camera_info.state.mode_video) // TODO video needs to be investigated, carried over from old code
909  {
911  }
912  else
913  {
914  // in an AF mode, set later
916  }
917  lua_pushboolean(L, 1);
918  return 1;
919 }
static int luaCB_set_focus_interlock_bypass ( lua_State L)
static

Definiert in Zeile 888 der Datei luascript.c.

889 {
891  return 0;
892 }
static int luaCB_set_iso_mode ( lua_State L)
static

Definiert in Zeile 921 der Datei luascript.c.

922 {
924  return 0;
925 }
static int luaCB_set_iso_real ( lua_State L)
static

Definiert in Zeile 927 der Datei luascript.c.

928 {
930  return 0;
931 }
static int luaCB_set_lcd_display ( lua_State L)
static

Definiert in Zeile 1901 der Datei luascript.c.

1902 {
1903  int val = on_off_value_from_lua_arg(L,1);
1904 
1905  if (val > 0) TurnOnDisplay();
1906  else TurnOffDisplay();
1907  return 0;
1908 }
static int luaCB_set_led ( lua_State L)
static

Definiert in Zeile 933 der Datei luascript.c.

934 {
935  int to, to1, to2;
936  to = luaL_checknumber( L, 1 );
937  to1 = luaL_checknumber( L, 2 );
938  to2 = 200;
939  if( lua_isnumber( L, 3 ) )
940  to2 = lua_tonumber( L, 3 );
941  camera_set_led(to, to1, to2);
942  return 0;
943 }
static int luaCB_set_levent_active ( lua_State L)
static

Definiert in Zeile 2051 der Datei luascript.c.

2052 {
2053  unsigned event_id;
2054  unsigned state;
2055 
2056  event_id = levent_id_from_lua_arg(L,1);
2057  state = on_off_value_from_lua_arg(L,2);
2058  SetLogicalEventActive(event_id,state);
2059  return 0;
2060 }
static int luaCB_set_levent_script_mode ( lua_State L)
static

Definiert in Zeile 2067 der Datei luascript.c.

2068 {
2070  return 0;
2071 }
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 1468 der Datei luascript.c.

1469 {
1471  return 0;
1472 }
static int luaCB_set_nd_filter ( lua_State L)
static

Definiert in Zeile 945 der Datei luascript.c.

946 {
948  return 0;
949 }
static int luaCB_set_prop ( lua_State L)
static

Definiert in Zeile 955 der Datei luascript.c.

956 {
958  return 0;
959 }
static int luaCB_set_prop_str ( lua_State L)
static

Definiert in Zeile 967 der Datei luascript.c.

967  {
968  int prop_id;
969  unsigned len;
970  const char *str;
971  prop_id = luaL_checknumber( L, 1 );
972  str = luaL_checklstring( L, 2, &len );
973  if(str && len > 0) {
974  lua_pushboolean( L, (set_property_case(prop_id,(void *)str,len) == 0));
975  } else {
976  return luaL_error( L, "invalid value");
977  }
978  return 1;
979 }
static int luaCB_set_raw ( lua_State L)
static

Definiert in Zeile 993 der Datei luascript.c.

994 {
996  return 0;
997 }
static int luaCB_set_raw_develop ( lua_State L)
static

Definiert in Zeile 1858 der Datei luascript.c.

1859 {
1861  return 0;
1862 }
static int luaCB_set_raw_nr ( lua_State L)
static

Definiert in Zeile 981 der Datei luascript.c.

982 {
983  conf.raw_nr = luaL_checknumber( L, 1 );
984  return 0;
985 }
static int luaCB_set_record ( lua_State L)
static

Definiert in Zeile 2123 der Datei luascript.c.

2124 {
2126  return 0;
2127 }
static int luaCB_set_remote_timing ( lua_State L)
static

Definiert in Zeile 1394 der Datei luascript.c.

1395 {
1396  int val= on_off_value_from_lua_arg(L,1);
1397  if (val > 0 )
1399  else
1401  return 1;
1402 }
static int luaCB_set_sv96 ( lua_State L)
static

Definiert in Zeile 1005 der Datei luascript.c.

1006 {
1008  return 0;
1009 }
static int luaCB_set_tv96 ( lua_State L)
static

Definiert in Zeile 1017 der Datei luascript.c.

1018 {
1020  return 0;
1021 }
static int luaCB_set_tv96_direct ( lua_State L)
static

Definiert in Zeile 1011 der Datei luascript.c.

1012 {
1014  return 0;
1015 }
static int luaCB_set_usb_capture_timeout ( lua_State L)
static

Definiert in Zeile 2665 der Datei luascript.c.

2666 {
2668  return 0;
2669 }
static int luaCB_set_user_av96 ( lua_State L)
static

Definiert in Zeile 1035 der Datei luascript.c.

1036 {
1038  return 0;
1039 }
static int luaCB_set_user_av_by_id ( lua_State L)
static

Definiert in Zeile 1029 der Datei luascript.c.

1030 {
1032  return 0;
1033 }
static int luaCB_set_user_av_by_id_rel ( lua_State L)
static

Definiert in Zeile 1023 der Datei luascript.c.

1024 {
1026  return 0;
1027 }
static int luaCB_set_user_tv96 ( lua_State L)
static

Definiert in Zeile 1053 der Datei luascript.c.

1054 {
1056  return 0;
1057 }
static int luaCB_set_user_tv_by_id ( lua_State L)
static

Definiert in Zeile 1047 der Datei luascript.c.

1048 {
1050  return 0;
1051 }
static int luaCB_set_user_tv_by_id_rel ( lua_State L)
static

Definiert in Zeile 1041 der Datei luascript.c.

1042 {
1044  return 0;
1045 }
static int luaCB_set_yield ( lua_State L)
static

Definiert in Zeile 2603 der Datei luascript.c.

static int luaCB_set_zoom ( lua_State L)
static

Definiert in Zeile 1071 der Datei luascript.c.

1072 {
1074  return 0;
1075 }
static int luaCB_set_zoom_rel ( lua_State L)
static

Definiert in Zeile 1065 der Datei luascript.c.

1066 {
1068  return 0;
1069 }
static int luaCB_set_zoom_speed ( lua_State L)
static

Definiert in Zeile 1059 der Datei luascript.c.

1060 {
1062  return 0;
1063 }
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 2770 der Datei luascript.c.

2771 {
2772  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2774  return 0;
2775 }
static int luaCB_shoot_hook_count ( lua_State L)
static

Definiert in Zeile 2782 der Datei luascript.c.

2783 {
2784  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2786  return 1;
2787 }
static int luaCB_shoot_hook_is_ready ( lua_State L)
static

Definiert in Zeile 2759 der Datei luascript.c.

2760 {
2761  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2763  return 1;
2764 }
static int luaCB_shoot_hook_set ( lua_State L)
static

Definiert in Zeile 2748 der Datei luascript.c.

2749 {
2750  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2752  return 0;
2753 }
static int luaCB_shot_histo_enable ( lua_State L)
static

Definiert in Zeile 1593 der Datei luascript.c.

1594 {
1596  return 0;
1597 }
static int luaCB_shot_histo_write_to_file ( lua_State L)
static

Definiert in Zeile 1599 der Datei luascript.c.

1600 {
1602  return 0;
1603 }
static int luaCB_shut_down ( lua_State L)
static

Definiert in Zeile 1445 der Datei luascript.c.

1446 {
1447  if ( luaL_optnumber(L,1,0) == 1 )
1448  {
1449  shutdown();
1450  } else {
1452  }
1453  return 0;
1454 }
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 2704 der Datei luascript.c.

2705 {
2707  return 1;
2708 }
static int luaCB_sv96_real_to_market ( lua_State L)
static

Definiert in Zeile 2698 der Datei luascript.c.

2699 {
2701  return 1;
2702 }
static int luaCB_sv96_to_iso ( lua_State L)
static

Definiert in Zeile 2680 der Datei luascript.c.

2681 {
2683  return 1;
2684 }
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 2131 der Datei luascript.c.

2132 {
2134  return 0;
2135 }
static int luaCB_textbox ( lua_State L)
static

Definiert in Zeile 1246 der Datei luascript.c.

1246  {
1247  // Disconnect button input from script so buttons will work in the textbox
1249  // Switch to textbox gui mode. Text box prompt should be passed as param.
1250  int rv = libtextbox->textbox_init((int)luaL_optstring( L, 1, "Text box" ), //title
1251  (int)luaL_optstring( L, 2, "Enter text" ), //message
1252  luaL_optstring( L, 3, "" ), //default string
1253  luaL_optnumber( L, 4, 30), //max size of a text
1255  if (rv)
1256  {
1257  // Push textbox action onto stack - will loop doing nothing until textbox exits
1259  }
1260  else
1262 
1263  // Yield the script so that the action stack will process the AS_TEXTBOX action
1264  return lua_yield(L, 0);
1265 }
static int luaCB_tv96_to_usec ( lua_State L)
static

Definiert in Zeile 2728 der Datei luascript.c.

2729 {
2730  lua_pushnumber(L, (int)(shooting_get_shutter_speed_from_tv96(luaL_checknumber(L, 1)) * 1000000.0 + 0.5));
2731  return 1;
2732 }
static int luaCB_usb_force_active ( lua_State L)
static

Definiert in Zeile 1405 der Datei luascript.c.

1406 {
1408  return 1;
1409 }
static int luaCB_usb_sync_wait ( lua_State L)
static

Definiert in Zeile 1412 der Datei luascript.c.

1413 {
1415  return 0;
1416 }
static int luaCB_usec_to_tv96 ( lua_State L)
static

Definiert in Zeile 2722 der Datei luascript.c.

2723 {
2725  return 1;
2726 }
static int luaCB_wait_click ( lua_State L)
static

Definiert in Zeile 1096 der Datei luascript.c.

1097 {
1098  int delay = luaL_optnumber( L, 1, 0 );
1099  if (delay == 0) delay = -1;
1100  delay = sleep_delay(delay);
1101 
1102  // Reset 'clicked' key if it has not changed since last time
1104  {
1106  }
1107 
1108  // Set up for wait or click testing
1109  action_push(delay);
1111 
1112  // Check for short delay or key already pressed by calling action stack routine once now
1113  if (action_stack_AS_LUA_WAIT_CLICK() == 0)
1114  {
1115  return lua_yield( L, 0 );
1116  }
1117 
1118  return 0;
1119 }
static int luaCB_wheel_left ( lua_State L)
static

Definiert in Zeile 1146 der Datei luascript.c.

1147 {
1148  JogDial_CCW();
1149  return 0;
1150 }
static int luaCB_wheel_right ( lua_State L)
static

Definiert in Zeile 1140 der Datei luascript.c.

1141 {
1142  JogDial_CW();
1143  return 0;
1144 }
static int luaCB_write_usb_msg ( lua_State L)
static

Definiert in Zeile 2478 der Datei luascript.c.

2479 {
2480  ptp_script_msg *msg;
2481  int timeout = sleep_delay(luaL_optnumber(L,2,0));
2482  // TODO would it be better to either ignore this or return nil ?
2483  // a write_usb_msg(function_which_returns_no_value()) is an error in this case
2484  // replacing with nil might be more luaish
2485  if (lua_gettop(L) < 1)
2486  {
2487  return luaL_error(L,"missing argument");
2488  }
2490  // for user messages, trying to create a message from an incompatible type throws an error
2491  if (msg->subtype == PTP_CHDK_TYPE_UNSUPPORTED)
2492  {
2493  free(msg);
2494  return luaL_error(L,"unsupported type");
2495  }
2496  if (!msg)
2497  {
2498  return luaL_error(L,"failed to create message");
2499  }
2500  if (timeout)
2501  {
2502  action_push(timeout);
2503  action_push((int)msg);
2505  return lua_yield( L, 0 );
2506  }
2508  return 1;
2509 }
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 2158 der Datei luascript.c.

2159 {
2160  unsigned i;
2161  unsigned end = lua_gettop(L);
2162 
2163  for(i = start; i <= end; i++,argbuf++) {
2164  if (lua_type(L, i) == LUA_TSTRING) {
2165  *argbuf=(unsigned)lua_tostring( L, i);
2166  }
2167  else if (lua_type(L, i) == LUA_TNUMBER) {
2168  *argbuf=lua_tonumber( L, i);
2169  }
2170  else {
2171  return 0;
2172  }
2173  }
2174  return 1;
2175 }
void register_lua_funcs ( lua_State L)

Definiert in Zeile 3039 der Datei luascript.c.

3040 {
3041  const luaL_reg *r;
3042 
3043  register_shoot_hooks( L );
3044  luaopen_rawop( L );
3045 
3048  lua_setglobal( L, "click" );
3049 
3052  lua_setglobal( L, "press" );
3053 
3056  lua_setglobal( L, "release" );
3057 
3058  for(r=chdk_funcs;r->name;r++) {
3059  lua_pushcfunction( L, r->func );
3060  lua_setglobal( L, r->name );
3061  }
3062  luaL_dostring(L,"function usb_msg_table_to_string(t)"
3063  " local v2s=function(v)"
3064  " local t=type(v)"
3065  " if t=='string' then return v end"
3066  " if t=='number' or t=='boolean' or t=='nil' then return tostring(v) end"
3067  " return '' end"
3068  " local r=''"
3069  " for k,v in pairs(t) do"
3070  " local s,vs=''"
3071  " if type(v)=='table' then"
3072  " for i=1,table.maxn(v) do"
3073  " s=s..'\\t'..v2s(v[i]) end"
3074  " else"
3075  " vs=v2s(v)"
3076  " if #vs then s=s..'\\t'..vs end"
3077  " end"
3078  " vs=v2s(k)"
3079  " if #vs>0 and #s>0 then r=r..vs..s..'\\n' end"
3080  " end"
3081  " return r"
3082  " end");
3083 
3084 }
void register_shoot_hook_fn ( lua_State L,
int  hook,
void *  hook_fn,
const char *  name 
)

Definiert in Zeile 3018 der Datei luascript.c.

3019 {
3020  lua_pushnumber( L, hook );
3021  lua_pushcclosure( L, hook_fn, 1 );
3022  lua_setfield( L, -2, name);
3023 }
void register_shoot_hooks ( lua_State L)

Definiert in Zeile 3025 der Datei luascript.c.

3026 {
3027  int i;
3028  for(i=0; i<SCRIPT_NUM_SHOOT_HOOKS;i++) {
3029  lua_createtable(L, 0, 4);
3031 // register_shoot_hook_fn(L,i,luaCB_shoot_hook_wait_ready,"wait_ready");
3036  }
3037 }
static void return_string_selected ( const char *  str)
static

Definiert in Zeile 1213 der Datei luascript.c.

1213  {
1214  // Reconnect button input to script - will also signal action stack
1215  // that file browser / textbox is finished and return last selected file
1216  // to script caller
1218 
1219  // Push selected file as script return value
1220  lua_pushstring( Lt, (str && str[0])? str : NULL );
1221 }
static void set_meminfo_num ( lua_State L,
const char *  name,
int  val 
)
static

Definiert in Zeile 2512 der Datei luascript.c.

2512  {
2513  if(val != -1) {
2514  set_number_field( L, name, val );
2515  }
2516 }
void set_number_field ( lua_State L,
const char *  key,
int  val 
)

Definiert in Zeile 1827 der Datei luascript.c.

1828 {
1829  lua_pushnumber(L, val);
1830  lua_setfield(L, -2, key);
1831 }
void set_string_field ( lua_State L,
const char *  key,
const char *  val 
)

Definiert in Zeile 1821 der Datei luascript.c.

1822 {
1823  lua_pushstring(L, val);
1824  lua_setfield(L, -2, key);
1825 }
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 2792 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.