CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
luascript.c-Dateireferenz
#include "camera_info.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 "time.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 "lualib.h"
#include "lauxlib.h"
#include "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, __attribute__((unused)) 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 (__attribute__((unused)) 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 (__attribute__((unused)) 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_current_delta_sv96 (lua_State *L)
 
static int luaCB_get_current_base_sv96 (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 (__attribute__((unused)) lua_State *L)
 
static int luaCB_wheel_left (__attribute__((unused)) 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 (__attribute__((unused)) 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 (__attribute__((unused)) lua_State *L)
 
static int luaCB_exit_alt (__attribute__((unused)) 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 (__attribute__((unused)) 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 (__attribute__((unused)) 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 unsigned 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 2809 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 449 der Datei luascript.c.

450 {
451  if (get_tick_count() >= action_top(2))
452  {
453  action_pop_func(1);
454  return 1;
455  }
456  return 0;
457 }
static int action_stack_AS_LUA_WAIT_CLICK ( )
static

Definiert in Zeile 1096 der Datei luascript.c.

1097 {
1098  // Check key pressed or timeout
1100  {
1101  // If timed out set key state to "no_key", otherwise key pressed so set last checked time
1104  else
1106 
1107  action_pop_func(1);
1108  return 1;
1109  }
1110 
1111  return 0;
1112 }
static int action_stack_AS_SCRIPT_READ_USB_MSG ( )
static

Definiert in Zeile 2427 der Datei luascript.c.

2428 {
2430 
2431  if ((get_tick_count() >= action_top(2)) || msg)
2432  {
2433  if (msg && msg->data)
2434  {
2435  lua_pushlstring(Lt,msg->data,msg->size);
2436  }
2437  else
2438  {
2439  lua_pushnil(Lt);
2440  }
2441  action_pop_func(1);
2442  return 1;
2443  }
2444  return 0;
2445 }
static int action_stack_AS_SCRIPT_WRITE_USB_MSG ( )
static

Definiert in Zeile 2447 der Datei luascript.c.

2448 {
2450 
2451  int r = ptp_script_write_msg(msg);
2452 
2453  if ((get_tick_count() >= action_top(3)) || r)
2454  {
2455  lua_pushboolean(Lt,r);
2456  action_pop_func(2);
2457  return 1;
2458  }
2459  return 0;
2460 }
static int action_stack_AS_WAIT_MODULE ( )
static

Definiert in Zeile 1241 der Datei luascript.c.

1242 {
1243  // state_kbd_script_run is set to 0 when the file browser is started from a Lua script
1244  // it is reset back to 1 when the file browser exits and control is returned back to
1245  // the script
1247  {
1248  action_pop_func(0);
1249  }
1250  return 0;
1251 }
static unsigned levent_id_from_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 1943 der Datei luascript.c.

1944 {
1945  unsigned event_id;
1946  if (lua_type(L, index) == LUA_TSTRING) {
1947  const char *ev_name = lua_tostring(L, index);
1948  event_id = levent_id_for_name(ev_name);
1949  if (event_id == 0) {
1950  return luaL_error( L, "bad event name '%s'", ev_name );
1951  }
1952  }
1953  // could check here if it is in the table, but even valid ones can crash
1954  // so we avoid searching the table if given a number
1955  else if (lua_type(L,index) == LUA_TNUMBER){
1956  event_id = lua_tonumber(L,index);
1957  }
1958  else {
1959  return luaL_error( L, "expected event name or id" );
1960  }
1961  return event_id;
1962 }
static unsigned levent_index_from_id_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 1968 der Datei luascript.c.

1969 {
1970  if (lua_type(L, index) == LUA_TSTRING) {
1971  return levent_index_for_name(lua_tostring(L, index));
1972  }
1973  else if (lua_type(L,index) == LUA_TNUMBER){
1974  return levent_index_for_id(lua_tonumber(L,index));
1975  }
1976  else {
1977  return luaL_error( L, "expected string or number" );
1978  }
1979 }
static void lua_count_hook ( lua_State L,
__attribute__((unused)) lua_Debug ar 
)
static

Definiert in Zeile 193 der Datei luascript.c.

194 {
195  run_hook_count++;
196  if( L->nCcalls > L->baseCcalls || !yield_hook_enabled )
197  return;
199  lua_yield( L, 0 );
200 }
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 361 der Datei luascript.c.

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

Definiert in Zeile 347 der Datei luascript.c.

348 {
349  lua_getglobal(Lt, "restore");
350  if (lua_isfunction(Lt, -1)) {
351  if (lua_pcall( Lt, 0, 0, 0 )) {
352  script_console_add_line( (long)lua_tostring( Lt, -1 ) );
353  }
354  if (lua_script_is_ptp == 0)
356  }
357  return 0;
358 }
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 202 der Datei luascript.c.

203 {
204  const char *err = lua_tostring( Lt, -1 );
205 
206  if(err)
207  {
208  if(!*err)
209  {
210  script_console_add_error( (long)"ERROR: empty error message" );
211  }
212  else
213  {
214  script_console_add_error( (long)err );
215  }
216  }
217  else
218  {
219  script_console_add_error( (long)"ERROR: NULL error message" );
220  }
221 
222  if (lua_script_is_ptp)
223  {
224  lua_script_error_ptp(runtime,err);
225  }
226  else
227  {
228  if (runtime)
229  {
231  script_end();
232  script_start_gui(0);
233  return SCRIPT_RUN_RUNNING;
234  }
235  }
236  else // ensure lua_state is closed for compiletime errors
237  {
239  }
240  }
241 
243  return SCRIPT_RUN_ERROR;
244 }
void lua_script_error_ptp ( int  runtime,
const char *  err 
)

Definiert in Zeile 184 der Datei luascript.c.

184  {
185  if(runtime) {
187  } else {
190  }
191 }
void lua_script_finish ( lua_State L)

Definiert in Zeile 248 der Datei luascript.c.

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

Definiert in Zeile 168 der Datei luascript.c.

169 {
170  // in PTP, clean up gui state to ensure not left in script handler
171  if(lua_script_is_ptp) {
172  if(ptp_saved_alt_state) {
173  enter_alt(0); // return to regular "alt" from script GUI mode
174  } else {
175  exit_alt();
176  }
177  }
178 
180  lua_close( L );
181  L = 0;
182 }
int lua_script_run ( void  )

Definiert in Zeile 310 der Datei luascript.c.

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

Definiert in Zeile 271 der Datei luascript.c.

272 {
274  lua_script_is_ptp = ptp;
275  if(ptp) {
277  // put ui in script alt state to allow key presses to be sent to script
278  enter_alt(1);
279  }
280  L = lua_open();
281  luaL_openlibs( L );
283 
284  Lt = lua_newthread( L );
285  lua_setfield( L, LUA_REGISTRYINDEX, "Lt" );
286  if( luaL_loadstring( Lt, script ) != 0 )
287  {
288  lua_script_error(Lt,0);
289  return 0;
290  }
293  run_first_resume = 1;
296  return 1;
297 }
int lua_script_start_file ( char const filename)

Definiert in Zeile 299 der Datei luascript.c.

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

Definiert in Zeile 3137 der Datei luascript.c.

3137 { 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 3112 der Datei luascript.c.

3113 {
3114  lua_pushstring( L, name );
3115  if (isTable)
3116  {
3117  lua_createtable(L, labelCount, 2);
3118  int i;
3119  for (i=0; i<labelCount; i++)
3120  {
3121  lua_pushstring(L,labels[i]);
3122  lua_rawseti(L,-2,i+1);
3123  }
3124  SET_INT_FIELD("index", value+1); // Make value 1 based for Lua table index
3125  SET_STR_FIELD("value", labels[value]);
3126  }
3127  else
3128  {
3129  if (isBool)
3130  lua_pushboolean( L, value );
3131  else
3132  lua_pushnumber( L, value );
3133  }
3135 }
static int luaCB_aperture_to_av96 ( lua_State L)
static

Definiert in Zeile 2728 der Datei luascript.c.

2729 {
2731  return 1;
2732 }
static int luaCB_autostarted ( lua_State L)
static

Definiert in Zeile 1384 der Datei luascript.c.

1385 {
1387  return 1;
1388 }
static int luaCB_av96_to_aperture ( lua_State L)
static

Definiert in Zeile 2734 der Datei luascript.c.

2735 {
2737  return 1;
2738 }
static int luaCB_bitand ( lua_State L)
static

Definiert in Zeile 1784 der Datei luascript.c.

1785 {
1786  int v1 = (luaL_checknumber(L,1));
1787  int v2 = (luaL_checknumber(L,2));
1788  lua_pushnumber( L, v1 & v2 );
1789  return 1;
1790 }
static int luaCB_bitnot ( lua_State L)
static

Definiert in Zeile 1832 der Datei luascript.c.

1833 {
1834  unsigned val = (luaL_checknumber(L,1));
1835  lua_pushnumber( L, ~val );
1836  return 1;
1837 }
static int luaCB_bitor ( lua_State L)
static

Definiert in Zeile 1792 der Datei luascript.c.

1793 {
1794  int v1 = (luaL_checknumber(L,1));
1795  int v2 = (luaL_checknumber(L,2));
1796  lua_pushnumber( L, v1 | v2 );
1797  return 1;
1798 }
static int luaCB_bitshl ( lua_State L)
static

Definiert in Zeile 1808 der Datei luascript.c.

1809 {
1810  int val = (luaL_checknumber(L,1));
1811  unsigned shift = (luaL_checknumber(L,2));
1812  lua_pushnumber( L, val << shift );
1813  return 1;
1814 }
static int luaCB_bitshri ( lua_State L)
static

Definiert in Zeile 1816 der Datei luascript.c.

1817 {
1818  int val = (luaL_checknumber(L,1));
1819  unsigned shift = (luaL_checknumber(L,2));
1820  lua_pushnumber( L, val >> shift );
1821  return 1;
1822 }
static int luaCB_bitshru ( lua_State L)
static

Definiert in Zeile 1824 der Datei luascript.c.

1825 {
1826  unsigned val = (luaL_checknumber(L,1));
1827  unsigned shift = (luaL_checknumber(L,2));
1828  lua_pushnumber( L, val >> shift );
1829  return 1;
1830 }
static int luaCB_bitxor ( lua_State L)
static

Definiert in Zeile 1800 der Datei luascript.c.

1801 {
1802  int v1 = (luaL_checknumber(L,1));
1803  int v2 = (luaL_checknumber(L,2));
1804  lua_pushnumber( L, v1 ^ v2 );
1805  return 1;
1806 }
static int luaCB_call_event_proc ( lua_State L)
static

Definiert in Zeile 2270 der Datei luascript.c.

2271 {
2273  {
2274  const char *evpname;
2275  unsigned *argbuf;
2276  unsigned n_args = lua_gettop(L);
2277 
2278  evpname=luaL_checkstring( L, 1 );
2279 
2280  argbuf=malloc(n_args * 4);
2281  if (!argbuf)
2282  {
2283  return luaL_error( L, "malloc fail" );
2284  }
2285 
2286  // event proc name is first arg
2287  *argbuf = (unsigned)evpname;
2288 
2289  if(!pack_native_args(L,2,argbuf+1))
2290  {
2291  free(argbuf);
2292  return luaL_error( L, "expected string or number" );
2293  }
2294 
2296  free(argbuf);
2297  return 1;
2298  }
2299  return luaL_error( L, "native calls disabled" );
2300 }
static int luaCB_call_func_ptr ( lua_State L)
static

Definiert in Zeile 2216 der Datei luascript.c.

2217 {
2219  {
2220  unsigned *argbuf=NULL;
2221  unsigned n_args = lua_gettop(L)-1;
2222  void *fptr;
2223 
2224  fptr=(void *)luaL_checknumber( L, 1 );
2225 
2226  if (n_args)
2227  {
2228  argbuf=malloc(n_args * 4);
2229  if(!argbuf)
2230  {
2231  return luaL_error( L, "malloc fail" );
2232  }
2233  if(!pack_native_args(L, 2, argbuf))
2234  {
2235  free(argbuf);
2236  return luaL_error( L, "expected string or number" );
2237  }
2238  }
2239 
2240  lua_pushnumber( L, call_func_ptr(fptr, argbuf, n_args) );
2241  free(argbuf);
2242  return 1;
2243  }
2244  return luaL_error( L, "native calls disabled" );
2245 }
static int luaCB_cls ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 492 der Datei luascript.c.

493 {
494  console_clear();
495  return 0;
496 }
static int luaCB_console_redraw ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 510 der Datei luascript.c.

511 {
512  console_redraw();
513  return 0;
514 }
static int luaCB_draw_clear ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 1365 der Datei luascript.c.

1365  {
1366  draw_restore();
1367  return 0;
1368 }
static int luaCB_draw_ellipse ( lua_State L)
static

Definiert in Zeile 1327 der Datei luascript.c.

1327  {
1328  coord x1=luaL_checknumber(L,1);
1329  coord y1=luaL_checknumber(L,2);
1330  coord a=luaL_checknumber(L,3);
1331  coord b=luaL_checknumber(L,4);
1333  draw_ellipse(x1,y1,a,b,cl,0);
1334  return 0;
1335 }
static int luaCB_draw_ellipse_filled ( lua_State L)
static

Definiert in Zeile 1337 der Datei luascript.c.

1337  {
1338  coord x1=luaL_checknumber(L,1);
1339  coord y1=luaL_checknumber(L,2);
1340  coord a=luaL_checknumber(L,3);
1341  coord b=luaL_checknumber(L,4);
1343  draw_ellipse(x1,y1,a,b,cl,DRAW_FILLED);
1344  return 0;
1345 }
static int luaCB_draw_line ( lua_State L)
static

Definiert in Zeile 1294 der Datei luascript.c.

1294  {
1295  coord x1=luaL_checknumber(L,1);
1296  coord y1=luaL_checknumber(L,2);
1297  coord x2=luaL_checknumber(L,3);
1298  coord y2=luaL_checknumber(L,4);
1300  draw_line(x1,y1,x2,y2,cl);
1301  return 0;
1302 }
static int luaCB_draw_pixel ( 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);
1290  draw_pixel(x1,y1,cl);
1291  return 0;
1292 }
static int luaCB_draw_rect ( lua_State L)
static

Definiert in Zeile 1304 der Datei luascript.c.

1304  {
1305  coord x1=luaL_checknumber(L,1);
1306  coord y1=luaL_checknumber(L,2);
1307  coord x2=luaL_checknumber(L,3);
1308  coord y2=luaL_checknumber(L,4);
1310  int th=luaL_optnumber(L,6,1) & RECT_BORDER_MASK;
1311  draw_rectangle(x1,y1,x2,y2,MAKE_COLOR(cl,cl),th);
1312  return 0;
1313 }
static int luaCB_draw_rect_filled ( lua_State L)
static

Definiert in Zeile 1315 der Datei luascript.c.

1315  {
1316  coord x1 =luaL_checknumber(L,1);
1317  coord y1 =luaL_checknumber(L,2);
1318  coord x2 =luaL_checknumber(L,3);
1319  coord y2 =luaL_checknumber(L,4);
1322  int th =luaL_optnumber(L,7,1) & RECT_BORDER_MASK;
1323  draw_rectangle(x1,y1,x2,y2,MAKE_COLOR(clb,clf),th|DRAW_FILLED);
1324  return 0;
1325 }
static int luaCB_draw_string ( lua_State L)
static

Definiert in Zeile 1347 der Datei luascript.c.

1348 {
1349  coord x1 = luaL_checknumber(L,1);
1350  coord y1 = luaL_checknumber(L,2);
1351  const char *t = luaL_checkstring( L, 3 );
1354  int xsize = luaL_optnumber(L,6,1);
1355  int ysize = luaL_optnumber(L,7,xsize);
1356 
1357  if ((xsize <= 1) && (ysize <= 1))
1358  draw_string(x1, y1, t, MAKE_COLOR(clb,clf));
1359  else
1360  draw_string_scaled(x1, y1, t, MAKE_COLOR(clb,clf), xsize, ysize);
1361 
1362  return 0;
1363 }
static int luaCB_enter_alt ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 1436 der Datei luascript.c.

1437 {
1438  enter_alt(1);
1439  // if alt explicitly changed by script, set as 'saved' state
1440  if(lua_script_is_ptp) {
1441  ptp_saved_alt_state = 1;
1442  }
1443  return 0;
1444 }
static int luaCB_exit_alt ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 1446 der Datei luascript.c.

1447 {
1448  exit_alt();
1449  // if alt explicitly changed by script, set as 'saved' state
1450  if(lua_script_is_ptp) {
1451  ptp_saved_alt_state = 0;
1452  }
1453  return 0;
1454 }
static int luaCB_file_browser ( lua_State L)
static

Definiert in Zeile 1253 der Datei luascript.c.

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

Definiert in Zeile 2165 der Datei luascript.c.

2166 {
2168  return 1;
2169 }
static int luaCB_get_alt_mode ( lua_State L)
static

Definiert in Zeile 1456 der Datei luascript.c.

1457 {
1459  return 1 ;
1460 }
static int luaCB_get_autostart ( lua_State L)
static

Definiert in Zeile 1390 der Datei luascript.c.

1391 {
1393  return 1;
1394 }
static int luaCB_get_av96 ( lua_State L)
static

Definiert in Zeile 552 der Datei luascript.c.

553 {
555  return 1;
556 }
static int luaCB_get_buildinfo ( lua_State L)
static

Definiert in Zeile 1851 der Datei luascript.c.

1852 {
1853  lua_createtable(L, 0, 10);
1854  set_string_field( L,"platform", camera_info.platform );
1855  set_string_field( L,"platsub", camera_info.platformsub );
1856  set_string_field( L,"version", camera_info.chdk_ver );
1857  set_string_field( L,"build_number", camera_info.build_number );
1858  set_string_field( L,"build_revision", camera_info.build_svnrev );
1859  set_string_field( L,"build_date", camera_info.build_date );
1860  set_string_field( L,"build_time", camera_info.build_time );
1861  set_string_field( L,"os", camera_info.os );
1862  set_number_field( L,"platformid", conf.platformid );
1863  set_number_field( L,"digic", camera_info.cam_digic );
1864  return 1;
1865 }
static int luaCB_get_bv96 ( lua_State L)
static

Definiert in Zeile 558 der Datei luascript.c.

559 {
561  return 1;
562 }
static int luaCB_get_canon_image_format ( lua_State L)
static

Definiert in Zeile 811 der Datei luascript.c.

812 {
814  return 1;
815 }
static int luaCB_get_canon_raw_support ( lua_State L)
static

Definiert in Zeile 818 der Datei luascript.c.

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

Definiert in Zeile 2313 der Datei luascript.c.

2313  {
2314  unsigned int argc = lua_gettop(L);
2315  unsigned int id, i;
2316  int ret = 1;
2317  tConfigVal configVal;
2318 
2319  if( argc>=1 ) {
2320  id = luaL_checknumber(L, 1);
2321  switch( conf_getValue(id, &configVal) ) {
2322  case CONF_VALUE:
2323  lua_pushnumber(L, configVal.numb);
2324  break;
2325  case CONF_INT_PTR:
2326  lua_createtable(L, 0, configVal.numb);
2327  for( i=0; i<(unsigned)configVal.numb; i++ ) {
2328  lua_pushinteger(L, configVal.pInt[i]);
2329  lua_rawseti(L, -2, i+1); //t[i+1]=configVal.pInt[i]
2330  }
2331  break;
2332  case CONF_CHAR_PTR:
2333  lua_pushstring(L, configVal.str);
2334  break;
2335  case CONF_OSD_POS:
2336  lua_pushnumber(L, configVal.pos.x);
2337  lua_pushnumber(L, configVal.pos.y); ret++;
2338  break;
2339  default:
2340  if( argc>=2) { //Default
2341  ret = argc-1;
2342  } else {
2343  lua_pushnil(L);
2344  }
2345  break;
2346  }
2347  } else {
2348  lua_pushnil(L);
2349  }
2350  return ret;
2351 }
static int luaCB_get_current_av96 ( lua_State L)
static

Definiert in Zeile 755 der Datei luascript.c.

756 {
758  return 1;
759 }
static int luaCB_get_current_base_sv96 ( lua_State L)
static

Definiert in Zeile 782 der Datei luascript.c.

783 {
785  return 1;
786 }
static int luaCB_get_current_delta_sv96 ( lua_State L)
static

Definiert in Zeile 775 der Datei luascript.c.

776 {
778  return 1;
779 }
static int luaCB_get_current_tv96 ( lua_State L)
static

Definiert in Zeile 763 der Datei luascript.c.

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

Definiert in Zeile 405 der Datei luascript.c.

406 {
408  return 1;
409 }
static int luaCB_get_curve_state ( lua_State L)
static

Definiert in Zeile 391 der Datei luascript.c.

392 {
394  return 1;
395 }
static int luaCB_get_day_seconds ( lua_State L)
static

Definiert in Zeile 564 der Datei luascript.c.

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

Definiert in Zeile 572 der Datei luascript.c.

573 {
575  return 1;
576 }
static int luaCB_get_dofinfo ( lua_State L)
static
static int luaCB_get_draw_title_line ( lua_State L)
static

Definiert in Zeile 1936 der Datei luascript.c.

1937 {
1939  return 1;
1940 }
static int luaCB_get_drive_mode ( lua_State L)
static

Definiert in Zeile 1504 der Datei luascript.c.

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

Definiert in Zeile 1588 der Datei luascript.c.

1589 {
1591  return 1;
1592 }
static int luaCB_get_exp_count ( lua_State L)
static

Definiert in Zeile 698 der Datei luascript.c.

699 {
701  return 1;
702 }
static int luaCB_get_flash_mode ( lua_State L)
static

Definiert in Zeile 1528 der Datei luascript.c.

1529 {
1531  return 1;
1532 }
static int luaCB_get_flash_params_count ( lua_State L)
static

Definiert in Zeile 879 der Datei luascript.c.

880 {
882  return 1;
883 }
static int luaCB_get_flash_ready ( lua_State L)
static

Definiert in Zeile 1540 der Datei luascript.c.

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

Definiert in Zeile 603 der Datei luascript.c.

604 {
606  return 1;
607 }
static int luaCB_get_focus_mode ( lua_State L)
static

Definiert in Zeile 1510 der Datei luascript.c.

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

Definiert in Zeile 1522 der Datei luascript.c.

1523 {
1525  return 1;
1526 }
static int luaCB_get_focus_state ( lua_State L)
static

Definiert in Zeile 1516 der Datei luascript.c.

1517 {
1519  return 1;
1520 }
static int luaCB_get_free_disk_space ( lua_State L)
static

Definiert in Zeile 597 der Datei luascript.c.

598 {
600  return 1;
601 }
static int luaCB_get_gui_screen_height ( lua_State L)
static

Definiert in Zeile 1378 der Datei luascript.c.

1379 {
1381  return 1;
1382 }
static int luaCB_get_gui_screen_width ( lua_State L)
static

Definiert in Zeile 1372 der Datei luascript.c.

1373 {
1375  return 1;
1376 }
static int luaCB_get_histo_range ( lua_State L)
static

Definiert in Zeile 1603 der Datei luascript.c.

1604 {
1605  int from = (luaL_checknumber(L,1));
1606  int to = (luaL_checknumber(L,2));
1608  return 1;
1609 }
static int luaCB_get_image_dir ( lua_State L)
static

Definiert in Zeile 704 der Datei luascript.c.

705 {
706  char dir[32];
707  get_target_dir_name(dir);
708  lua_pushstring( L, dir );
709  return 1;
710 }
static int luaCB_get_imager_active ( lua_State L)
static

Definiert in Zeile 804 der Datei luascript.c.

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

Definiert in Zeile 1546 der Datei luascript.c.

1547 {
1549  return 1;
1550 }
static int luaCB_get_iso_market ( lua_State L)
static

Definiert in Zeile 609 der Datei luascript.c.

610 {
612  return 1;
613 }
static int luaCB_get_iso_mode ( lua_State L)
static

Definiert in Zeile 615 der Datei luascript.c.

616 {
618  return 1;
619 }
static int luaCB_get_iso_real ( lua_State L)
static

Definiert in Zeile 621 der Datei luascript.c.

622 {
624  return 1;
625 }
static int luaCB_get_jpg_count ( lua_State L)
static

Definiert in Zeile 627 der Datei luascript.c.

628 {
629  lua_pushnumber( L, GetJpgCount() );
630  return 1;
631 }
static int luaCB_get_levent_def ( 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  return 1;
1992  }
1993  lua_pushstring(L, levent_table[event_index].name);
1994  lua_pushnumber(L, levent_table[event_index].id);
1995  lua_pushnumber(L, levent_table[event_index].param);
1996  return 3;
1997 }
static int luaCB_get_levent_def_by_index ( lua_State L)
static

Definiert in Zeile 2021 der Datei luascript.c.

2022 {
2023  unsigned i = luaL_checknumber(L,1);
2024  if(i >= levent_count()) {
2025  lua_pushnil(L);
2026  return 1;
2027  }
2028  lua_pushstring(L, levent_table[i].name);
2029  lua_pushnumber(L, levent_table[i].id);
2030  lua_pushnumber(L, levent_table[i].param);
2031  return 3;
2032 }
static int luaCB_get_levent_index ( lua_State L)
static

Definiert in Zeile 2004 der Datei luascript.c.

2005 {
2006  unsigned event_index = levent_index_from_id_lua_arg(L,1);
2007  if (event_index == LEVENT_INVALID_INDEX) {
2008  lua_pushnil(L);
2009  }
2010  else {
2011  lua_pushnumber(L, event_index);
2012  }
2013  return 1;
2014 }
static int luaCB_get_live_histo ( lua_State L)
static

Definiert in Zeile 1629 der Datei luascript.c.

1630 {
1631  unsigned short *h = malloc(256*sizeof(short));
1632  if(!h) {
1633  return luaL_error(L,"malloc fail");
1634  }
1635  int total=live_histogram_read_y(h);
1636  lua_createtable(L, 0, 256);
1637  int i;
1638  for(i=0;i<256;i++) {
1639  lua_pushnumber(L,h[i]);
1640  lua_rawseti(L,-2,i);
1641  }
1642  free(h);
1643  lua_pushnumber(L,total);
1644  return 2;
1645 }
static int luaCB_get_max_av96 ( lua_State L)
static

Definiert in Zeile 743 der Datei luascript.c.

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

Definiert in Zeile 2563 der Datei luascript.c.

2563  {
2564  const char *heapname = luaL_optstring( L, 1, "combined" );
2565  cam_meminfo meminfo;
2566  if (strcmp(heapname,"combined") == 0) {
2567  GetCombinedMemInfo(&meminfo);
2568  meminfo.start_address=meminfo.end_address=-1; // not meaningful
2569  }
2570  else if (strcmp(heapname,"system") == 0)
2571  {
2572  GetMemInfo(&meminfo);
2573  }
2574  else if ((strcmp(heapname,"aram") == 0))
2575  {
2576  if(!GetARamInfo(&meminfo)) {
2577  lua_pushboolean(L,0);
2578  return 1;
2579  }
2580  }
2581  else if (strcmp(heapname,"exmem") == 0)
2582  {
2583  if(!GetExMemInfo(&meminfo)) {;
2584  lua_pushboolean(L,0);
2585  return 1;
2586  }
2587  }
2588  else
2589  {
2590  lua_pushboolean(L,0);
2591  return 1;
2592  }
2593  // adjust start and size, if CHDK is loaded at heap start
2594  if(meminfo.start_address == camera_info.text_start) {
2596  meminfo.total_size -= camera_info.memisosize;
2597  }
2598  lua_createtable(L, 0, 13); // might not always use 13, but doesn't hurt
2599  set_string_field( L,"name", heapname );
2600  // CHDK allocates from all available heaps now
2601  lua_pushboolean( L, 1);
2602  lua_setfield(L, -2, "chdk_malloc");
2603  set_number_field( L, "chdk_start", camera_info.text_start);
2604  set_number_field( L, "chdk_size", camera_info.memisosize );
2605  set_meminfo_num( L, "start_address", meminfo.start_address );
2606  set_meminfo_num( L, "end_address", meminfo.end_address);
2607  set_meminfo_num( L, "total_size", meminfo.total_size);
2608  set_meminfo_num( L, "allocated_size", meminfo.allocated_size);
2609  set_meminfo_num( L, "allocated_peak", meminfo.allocated_peak);
2610  set_meminfo_num( L, "allocated_count", meminfo.allocated_count);
2611  set_meminfo_num( L, "free_size", meminfo.free_size);
2612  set_meminfo_num( L, "free_block_max_size", meminfo.free_block_max_size);
2613  set_meminfo_num( L, "free_block_count", meminfo.free_block_count);
2614  return 1;
2615 }
static int luaCB_get_min_av96 ( lua_State L)
static

Definiert in Zeile 731 der Datei luascript.c.

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

Definiert in Zeile 1867 der Datei luascript.c.

1868 {
1872  return 3;
1873 }
static int luaCB_get_movie_status ( lua_State L)
static

Definiert in Zeile 1480 der Datei luascript.c.

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

Definiert in Zeile 797 der Datei luascript.c.

798 {
800  return 1;
801 }
static int luaCB_get_nd_present ( lua_State L)
static

Definiert in Zeile 1564 der Datei luascript.c.

1565 {
1566  int to;
1567  if (camera_info.cam_has_nd_filter == 0)
1568  {
1569  to = 0;
1570  }
1571  else
1572  {
1574  to = 1;
1575  else
1576  to = 2;
1577  }
1578  lua_pushnumber( L, to );
1579  return 1;
1580 }
static int luaCB_get_nd_value_ev96 ( lua_State L)
static

Definiert in Zeile 790 der Datei luascript.c.

791 {
793  return 1;
794 }
static int luaCB_get_orientation_sensor ( lua_State L)
static

Definiert in Zeile 1552 der Datei luascript.c.

1553 {
1555  return 1;
1556 }
static int luaCB_get_parameter_data ( lua_State L)
static

Definiert in Zeile 848 der Datei luascript.c.

849 {
850  unsigned size;
851  unsigned id = luaL_checknumber( L, 1 );
852  unsigned val;
853 
854  size = get_parameter_size(id);
855  if (size == 0) {
856  // return nil
857  return 0;
858  }
859  if (size >= 1 && size <= 4) {
860  val = 0;
861  get_parameter_data( id, &val, size );
862  lua_pushlstring( L, (char *)&val, size );
863  // for convenience, params that fit in a number are returned in one as a second result
864  lua_pushnumber( L, val );
865  return 2;
866  }
867  else {
868  char *buf = malloc(size);
869  if(!buf) {
870  luaL_error( L, "malloc failed in luaCB_get_parameter_data" );
871  }
872  get_parameter_data( id, buf, size );
873  lua_pushlstring( L, buf, size );
874  free(buf);
875  return 1;
876  }
877 }
static int luaCB_get_partitionInfo ( lua_State L)
static

Definiert in Zeile 516 der Datei luascript.c.

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

Definiert in Zeile 638 der Datei luascript.c.

639 {
641  return 1;
642 }
static int luaCB_get_prop_str ( lua_State L)
static

Definiert in Zeile 650 der Datei luascript.c.

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

Definiert in Zeile 1582 der Datei luascript.c.

1583 {
1585  return 1;
1586 }
static int luaCB_get_raw ( lua_State L)
static

Definiert in Zeile 1017 der Datei luascript.c.

1018 {
1020  return 1;
1021 }
static int luaCB_get_raw_count ( lua_State L)
static

Definiert in Zeile 680 der Datei luascript.c.

681 {
682  lua_pushnumber( L, GetRawCount() );
683  return 1;
684 }
static int luaCB_get_raw_nr ( lua_State L)
static

Definiert in Zeile 1005 der Datei luascript.c.

1006 {
1007  lua_pushnumber( L, conf.raw_nr );
1008  return 1;
1009 }
static int luaCB_get_raw_support ( lua_State L)
static

Definiert in Zeile 674 der Datei luascript.c.

675 {
677  return 1;
678 }
static int luaCB_get_sd_over_modes ( lua_State L)
static

Definiert in Zeile 436 der Datei luascript.c.

437 {
439  return 1;
440 }
static int luaCB_get_shooting ( lua_State L)
static

Definiert in Zeile 1534 der Datei luascript.c.

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

Definiert in Zeile 686 der Datei luascript.c.

687 {
689  return 1;
690 }
static int luaCB_get_temperature ( lua_State L)
static

Definiert in Zeile 1653 der Datei luascript.c.

1654 {
1655  int which = (luaL_checknumber( L, 1 ));
1656  int temp = -100; // do something insane if users passes bad value
1657  switch (which)
1658  {
1659  case 0:
1660  temp = get_optical_temp();
1661  break;
1662  case 1:
1663  temp = get_ccd_temp();
1664  break;
1665  case 2:
1666  temp = get_battery_temp();
1667  break;
1668  }
1669  lua_pushnumber( L, temp );
1670  return 1;
1671 }
static int luaCB_get_tick_count ( lua_State L)
static

Definiert in Zeile 692 der Datei luascript.c.

693 {
695  return 1;
696 }
static int luaCB_get_time ( lua_State L)
static

Definiert in Zeile 1673 der Datei luascript.c.

1674 {
1675  int r = -1;
1676  static struct tm *ttm;
1677  ttm = get_localtime();
1678  const char *t = luaL_checkstring( L, 1 );
1679  if (strncmp("s", t, 1)==0) r = ttm->tm_sec;
1680  else if (strncmp("m", t, 1)==0) r = ttm->tm_min;
1681  else if (strncmp("h", t, 1)==0) r = ttm->tm_hour;
1682  else if (strncmp("D", t, 1)==0) r = ttm->tm_mday;
1683  else if (strncmp("M", t, 1)==0) r = ttm->tm_mon+1;
1684  else if (strncmp("Y", t, 1)==0) r = 1900+ttm->tm_year;
1685  lua_pushnumber( L, r );
1686  return 1;
1687 }
static int luaCB_get_tv96 ( lua_State L)
static

Definiert in Zeile 712 der Datei luascript.c.

713 {
715  return 1;
716 }
static int luaCB_get_usb_capture_support ( lua_State L)
static

Definiert in Zeile 2638 der Datei luascript.c.

2639 {
2641  return 1;
2642 }
static int luaCB_get_usb_capture_target ( lua_State L)
static

Definiert in Zeile 2665 der Datei luascript.c.

2666 {
2668  return 1;
2669 }
static int luaCB_get_usb_power ( lua_State L)
static

Definiert in Zeile 1405 der Datei luascript.c.

1406 {
1407  lua_pushnumber( L, get_usb_power(luaL_optnumber( L, 1, 0 )) );
1408  return 1;
1409 }
static int luaCB_get_user_av96 ( lua_State L)
static

Definiert in Zeile 724 der Datei luascript.c.

725 {
727  return 1;
728 }
static int luaCB_get_user_av_id ( lua_State L)
static

Definiert in Zeile 718 der Datei luascript.c.

719 {
721  return 1;
722 }
static int luaCB_get_user_tv96 ( lua_State L)
static

Definiert in Zeile 830 der Datei luascript.c.

831 {
833  return 1;
834 }
static int luaCB_get_user_tv_id ( lua_State L)
static

Definiert in Zeile 824 der Datei luascript.c.

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

Definiert in Zeile 836 der Datei luascript.c.

837 {
839  return 1;
840 }
static int luaCB_get_video_button ( lua_State L)
static

Definiert in Zeile 1492 der Datei luascript.c.

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

Definiert in Zeile 1498 der Datei luascript.c.

1499 {
1501  return 1;
1502 }
static int luaCB_get_zoom ( lua_State L)
static

Definiert in Zeile 842 der Datei luascript.c.

843 {
845  return 1;
846 }
static int luaCB_get_zoom_steps ( lua_State L)
static

Definiert in Zeile 1558 der Datei luascript.c.

1559 {
1561  return 1;
1562 }
static int luaCB_init_usb_capture ( lua_State L)
static

Definiert in Zeile 2652 der Datei luascript.c.

2653 {
2654  int what=luaL_checknumber(L, 1);
2655  int startline=luaL_optnumber(L, 2, 0);
2656  int numlines=luaL_optnumber(L, 3, 0);
2657  lua_pushboolean(L,remotecap_set_target(what,startline,numlines));
2658  return 1;
2659 }
static int luaCB_is_capture_mode_valid ( lua_State L)
static

Definiert in Zeile 2123 der Datei luascript.c.

2124 {
2125  int modenum = luaL_checknumber(L,1);
2126  lua_pushboolean( L, shooting_mode_chdk2canon(modenum) != -1 );
2127  return 1;
2128 }
static int luaCB_is_key ( lua_State L)
static

Definiert in Zeile 1145 der Datei luascript.c.

1146 {
1148  return 1;
1149 }
static int luaCB_is_pressed ( lua_State L)
static

Definiert in Zeile 1139 der Datei luascript.c.

1140 {
1142  return 1;
1143 }
static int luaCB_iso_market_to_real ( lua_State L)
static

Definiert in Zeile 2710 der Datei luascript.c.

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

Definiert in Zeile 2704 der Datei luascript.c.

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

Definiert in Zeile 2692 der Datei luascript.c.

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

Definiert in Zeile 485 der Datei luascript.c.

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

Definiert in Zeile 2417 der Datei luascript.c.

2417  {
2419  return 1;
2420 }
static int luaCB_md_af_led_control ( lua_State L)
static

Definiert in Zeile 1170 der Datei luascript.c.

1171 {
1174  if ((camera_info.perf.md_af_on_time > 0) && (camera_info.cam_af_led >= 0)) {
1175  camera_info.perf.md_af_tuning = 1; // Enable MD testing with AF LED
1176  // clear previous values
1178  camera_info.perf.af_led.min = 0xFFFFFFFF;
1179  } else {
1180  camera_info.perf.md_af_tuning = 0; // Disable MD testing
1181  }
1182  return 0;
1183 }
static int luaCB_md_detect_motion ( lua_State L)
static

Definiert in Zeile 1198 der Datei luascript.c.

1199 {
1200  int columns = (luaL_optnumber(L,1,6));
1201  int rows = (luaL_optnumber(L,2,4));
1202  int pixel_measure_mode = (luaL_optnumber(L,3,1));
1203  int detection_timeout = (luaL_optnumber(L,4,10000));
1204  int measure_interval = (luaL_optnumber(L,5,7));
1205  int threshold = (luaL_optnumber(L,6,10));
1206  int draw_grid = (luaL_optnumber(L,7,1));
1207  // arg 8 is the return value in ubasic. We
1208  // ignore it here. - AUJ
1209  int clipping_region_mode = (luaL_optnumber(L,9,0));
1210  int clipping_region_column1 = (luaL_optnumber(L,10,0));
1211  int clipping_region_row1 = (luaL_optnumber(L,11,0));
1212  int clipping_region_column2 = (luaL_optnumber(L,12,0));
1213  int clipping_region_row2 = (luaL_optnumber(L,13,0));
1214  int parameters = (luaL_optnumber(L,14,1));
1215  int pixels_step = (luaL_optnumber(L,15,6));
1216  int msecs_before_trigger = (luaL_optnumber(L,16,0));
1217 
1219  columns, rows, pixel_measure_mode, detection_timeout,
1220  measure_interval, threshold, draw_grid,
1221  clipping_region_mode,
1222  clipping_region_column1, clipping_region_row1,
1223  clipping_region_column2, clipping_region_row2,
1224  parameters, pixels_step, msecs_before_trigger
1225  ))
1226  return lua_yield(L, 0);
1227  else
1228  return luaL_error( L, "md_init_motion_detector failed" );
1229 }
static int luaCB_md_get_cell_diff ( lua_State L)
static

Definiert in Zeile 1185 der Datei luascript.c.

1186 {
1188  return 1;
1189 }
static int luaCB_md_get_cell_val ( lua_State L)
static

Definiert in Zeile 1192 der Datei luascript.c.

1193 {
1195  return 1;
1196 }
static int luaCB_peek ( lua_State L)
static

Definiert in Zeile 1714 der Datei luascript.c.

1715 {
1716  unsigned addr = luaL_checknumber(L,1);
1717  unsigned size = luaL_optnumber(L, 2, 4);
1718  switch(size) {
1719  case 1:
1720  lua_pushnumber( L, *(unsigned char *)(addr) );
1721  break;
1722  case 2:
1723  if (addr & 0x1) {
1724  lua_pushnil(L);
1725  }
1726  else {
1727  lua_pushnumber( L, *(unsigned short *)(addr) );
1728  }
1729  break;
1730  case 4:
1731  if (addr & 0x3) {
1732  lua_pushnil(L);
1733  }
1734  else {
1735  lua_pushnumber( L, *(unsigned *)(addr) );
1736  }
1737  break;
1738  default:
1739  lua_pushnil(L);
1740 
1741  }
1742  return 1;
1743 }
static int luaCB_play_sound ( lua_State L)
static

Definiert in Zeile 1647 der Datei luascript.c.

1648 {
1649  play_sound(luaL_checknumber( L, 1 ));
1650  return 0;
1651 }
static int luaCB_poke ( lua_State L)
static

Definiert in Zeile 1751 der Datei luascript.c.

1752 {
1753  unsigned addr = luaL_checknumber(L,1);
1754  unsigned val = luaL_checknumber(L,2);
1755  unsigned size = luaL_optnumber(L, 3, 4);
1756  int status = 0;
1757  switch(size) {
1758  case 1:
1759  *(unsigned char *)(addr) = (unsigned char)val;
1760  status=1;
1761  break;
1762  case 2:
1763  if (!(addr & 0x1)) {
1764  *(unsigned short *)(addr) = (unsigned short)val;
1765  status=1;
1766  }
1767  break;
1768  case 4:
1769  if (!(addr & 0x3)) {
1770  *(unsigned *)(addr) = val;
1771  status=1;
1772  }
1773  break;
1774  }
1775  if(status) {
1776  lua_pushboolean(L,1);
1777  }
1778  else {
1779  lua_pushnil(L);
1780  }
1781  return 1;
1782 }
static int luaCB_post_levent_for_npt ( lua_State L)
static

Definiert in Zeile 2053 der Datei luascript.c.

2054 {
2055  unsigned event_id,arg;
2056 
2057  event_id = levent_id_from_lua_arg(L,1);
2058  arg = luaL_optnumber(L, 2, 0);
2059  PostLogicalEventForNotPowerType(event_id,arg);
2060  return 0;
2061 }
static int luaCB_post_levent_to_ui ( lua_State L)
static

Definiert in Zeile 2043 der Datei luascript.c.

2044 {
2045  unsigned event_id,arg;
2046 
2047  event_id = levent_id_from_lua_arg(L,1);
2048  arg = luaL_optnumber(L, 2, 0);
2049  PostLogicalEventToUI(event_id,arg);
2050  return 0;
2051 }
static int luaCB_print_screen ( lua_State L)
static

Definiert in Zeile 1474 der Datei luascript.c.

1475 {
1477  return 0;
1478 }
static int luaCB_raw_merge_add_file ( lua_State L)
static

Definiert in Zeile 1896 der Datei luascript.c.

1897 {
1899  return 1;
1900 }
static int luaCB_raw_merge_end ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 1902 der Datei luascript.c.

1903 {
1905  return 0;
1906 }
static int luaCB_raw_merge_start ( lua_State L)
static

Definiert in Zeile 1882 der Datei luascript.c.

1883 {
1884  int op = luaL_checknumber(L,1);
1885  if ((op == RAW_OPERATION_SUM || op == RAW_OPERATION_AVERAGE))
1886  {
1888  return 1;
1889  }
1890  else {
1891  return luaL_argerror(L,1,"invalid raw merge op");
1892  }
1893 }
static int luaCB_read_usb_msg ( lua_State L)
static

Definiert in Zeile 2468 der Datei luascript.c.

2469 {
2470  int timeout = sleep_delay(luaL_optnumber(L,1,0));
2471  if (timeout > 0)
2472  {
2473  action_push(timeout);
2475  return lua_yield( L, 0 );
2476  }
2478  if(msg)
2479  {
2480  lua_pushlstring(L,msg->data,msg->size);
2481  free(msg);
2482  return 1;
2483  }
2484  lua_pushnil(L);
2485  return 1;
2486 }
static int luaCB_reboot ( lua_State L)
static

Definiert in Zeile 2307 der Datei luascript.c.

2308 {
2309  lua_pushboolean(L, reboot(luaL_optstring( L, 1, NULL )));
2310  return 1;
2311 }
static int luaCB_save_config_file ( lua_State L)
static

Definiert in Zeile 2412 der Datei luascript.c.

2412  {
2414  return 1;
2415 }
static int luaCB_seconds_to_tv96 ( lua_State L)
static

Definiert in Zeile 2752 der Datei luascript.c.

2753 {
2755  return 1;
2756 }
static int luaCB_set_aelock ( lua_State L)
static

Definiert in Zeile 411 der Datei luascript.c.

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

Definiert in Zeile 419 der Datei luascript.c.

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

Definiert in Zeile 1396 der Datei luascript.c.

1397 {
1398  int to;
1399  to = luaL_checknumber( L, 1 );
1400  if ( to >= 0 && to <= 3 ) conf.script_startup = to;
1401  conf_save();
1402  return 0;
1403 }
static int luaCB_set_av96 ( lua_State L)
static

Definiert in Zeile 891 der Datei luascript.c.

892 {
894  return 0;
895 }
static int luaCB_set_av96_direct ( lua_State L)
static

Definiert in Zeile 885 der Datei luascript.c.

886 {
888  return 0;
889 }
static int luaCB_set_backlight ( lua_State L)
static

Definiert in Zeile 1909 der Datei luascript.c.

1910 {
1911  int val = on_off_value_from_lua_arg(L,1);
1912 
1913  if (val > 0) TurnOnBackLight();
1914  else TurnOffBackLight();
1915  return 0;
1916 }
static int luaCB_set_canon_image_format ( lua_State L)
static

Definiert in Zeile 900 der Datei luascript.c.

901 {
903  return 1;
904 }
static int luaCB_set_capture_mode ( lua_State L)
static

Definiert in Zeile 2111 der Datei luascript.c.

2112 {
2113  int modenum = luaL_checknumber(L,1);
2114  lua_pushboolean( L, shooting_set_mode_chdk(modenum) );
2115  return 1;
2116 }
static int luaCB_set_capture_mode_canon ( lua_State L)
static

Definiert in Zeile 2096 der Datei luascript.c.

2097 {
2098  int modenum = luaL_checknumber(L,1);
2099  // if the value as negative, assume it is a mistakenly sign extended PROPCASE_SHOOTING_MODE value
2100  if(modenum < 0)
2101  modenum &= 0xFFFF;
2103  return 1;
2104 }
static int luaCB_set_clock ( lua_State L)
static

Definiert in Zeile 1698 der Datei luascript.c.

1699 {
1700  set_clock(luaL_checknumber(L,1), // year, like 2020
1701  luaL_checknumber(L,2), // month, 1-12
1702  luaL_checknumber(L,3), // day, 1-31
1703  luaL_checknumber(L,4), // hour
1704  luaL_checknumber(L,5), // minute
1705  luaL_checknumber(L,6)); // second
1706  return 0;
1707 }
static int luaCB_set_config_autosave ( lua_State L)
static

Definiert in Zeile 2407 der Datei luascript.c.

2407  {
2409  return 0;
2410 }
static int luaCB_set_config_value ( lua_State L)
static

Definiert in Zeile 2353 der Datei luascript.c.

2353  {
2354  unsigned int argc = lua_gettop(L);
2355  unsigned int id, i, j;
2356  tConfigVal configVal = {0}; //initialize isXXX
2357 
2358  if( argc>=2 ) {
2359  id = luaL_checknumber(L, 1);
2360  for( i=2; i<=argc; i++) {
2361  switch( lua_type(L, i) ) {
2362  case LUA_TNUMBER:
2363  if( !configVal.isNumb ) {
2364  configVal.numb = luaL_checknumber(L, i);
2365  configVal.isNumb++;
2366  }
2367  switch( configVal.isPos ) {
2368  case 0: configVal.pos.x = luaL_checknumber(L, i); configVal.isPos++; break;
2369  case 1: configVal.pos.y = luaL_checknumber(L, i); configVal.isPos++; break;
2370  }
2371  break;
2372  case LUA_TSTRING:
2373  if( !configVal.isStr ) {
2374  configVal.str = (char*)luaL_checkstring(L, i);
2375  configVal.isStr++;
2376  }
2377  break;
2378  case LUA_TTABLE:
2379  if( !configVal.isPInt ) {
2380  configVal.numb = lua_objlen(L, i);
2381  if( configVal.pInt ) {
2382  free(configVal.pInt);
2383  configVal.pInt = NULL;
2384  }
2385  configVal.pInt = malloc(configVal.numb*sizeof(int));
2386  if( configVal.pInt ) {
2387  for( j=1; j<=(unsigned)configVal.numb; j++) {
2388  lua_rawgeti(L, i, j);
2389  configVal.pInt[j-1] = lua_tointeger(L, -1);
2390  lua_pop(L, 1);
2391  }
2392  }
2393  configVal.isPInt++;
2394  }
2395  break;
2396  }
2397  }
2398  lua_pushboolean(L, conf_setValue(id, configVal));
2399  if( configVal.pInt ) {
2400  free(configVal.pInt);
2401  configVal.pInt = NULL;
2402  }
2403  } else lua_pushboolean(L, 0);
2404  return 1;
2405 }
static int luaCB_set_console_autoredraw ( lua_State L)
static

Definiert in Zeile 504 der Datei luascript.c.

505 {
507  return 0;
508 }
static int luaCB_set_console_layout ( lua_State L)
static

Definiert in Zeile 498 der Datei luascript.c.

499 {
501  return 0;
502 }
static int luaCB_set_curve_file ( lua_State L)
static

Definiert in Zeile 397 der Datei luascript.c.

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

Definiert in Zeile 385 der Datei luascript.c.

386 {
388  return 0;
389 }
static int luaCB_set_draw_title_line ( lua_State L)
static

Definiert in Zeile 1929 der Datei luascript.c.

1930 {
1932  return 0;
1933 }
static int luaCB_set_ev ( lua_State L)
static

Definiert in Zeile 1594 der Datei luascript.c.

1595 {
1596  int to;
1597  to = luaL_checknumber( L, 1 );
1600  return 0;
1601 }
static int luaCB_set_exit_key ( lua_State L)
static

Definiert in Zeile 1151 der Datei luascript.c.

1152 {
1153  // TODO can't check if valid for this camera
1155  return 0;
1156 }
static int luaCB_set_file_attributes ( lua_State L)
static

Definiert in Zeile 2422 der Datei luascript.c.

2422  {
2424  return 1;
2425 }
static int luaCB_set_focus ( lua_State L)
static

Definiert in Zeile 912 der Datei luascript.c.

913 {
914  int sd = luaL_checknumber( L, 1 );
915  // if sd override not available now, fail immediately without calling set_focus
916  // to avoid unexpected results with SET_LATER
917  if(!shooting_can_focus())
918  {
919  lua_pushboolean(L, 0);
920  return 1;
921  }
922  // NOTE duplicated in modules/luascript.c and lib/ubasic/ubasic.c
923  // in AF lock or MF (canon or set by MF functions), set focus now
926  || camera_info.state.mode_video) // TODO video needs to be investigated, carried over from old code
927  {
929  }
930  else
931  {
932  // in an AF mode, set later
934  }
935  lua_pushboolean(L, 1);
936  return 1;
937 }
static int luaCB_set_focus_interlock_bypass ( lua_State L)
static

Definiert in Zeile 906 der Datei luascript.c.

907 {
909  return 0;
910 }
static int luaCB_set_iso_mode ( lua_State L)
static

Definiert in Zeile 939 der Datei luascript.c.

940 {
942  return 0;
943 }
static int luaCB_set_iso_real ( lua_State L)
static

Definiert in Zeile 945 der Datei luascript.c.

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

Definiert in Zeile 1919 der Datei luascript.c.

1920 {
1921  int val = on_off_value_from_lua_arg(L,1);
1922 
1923  if (val > 0) TurnOnDisplay();
1924  else TurnOffDisplay();
1925  return 0;
1926 }
static int luaCB_set_led ( lua_State L)
static

Definiert in Zeile 951 der Datei luascript.c.

952 {
953  int to, to1, to2;
954  to = luaL_checknumber( L, 1 );
955  to1 = luaL_checknumber( L, 2 );
956  to2 = 200;
957  if( lua_isnumber( L, 3 ) )
958  to2 = lua_tonumber( L, 3 );
959  camera_set_led(to, to1, to2);
960  return 0;
961 }
static int luaCB_set_levent_active ( lua_State L)
static

Definiert in Zeile 2069 der Datei luascript.c.

2070 {
2071  unsigned event_id;
2072  unsigned state;
2073 
2074  event_id = levent_id_from_lua_arg(L,1);
2075  state = on_off_value_from_lua_arg(L,2);
2076  SetLogicalEventActive(event_id,state);
2077  return 0;
2078 }
static int luaCB_set_levent_script_mode ( lua_State L)
static

Definiert in Zeile 2085 der Datei luascript.c.

2086 {
2088  return 0;
2089 }
static int luaCB_set_mf ( lua_State L)
static

Definiert in Zeile 427 der Datei luascript.c.

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

Definiert in Zeile 1486 der Datei luascript.c.

1487 {
1489  return 0;
1490 }
static int luaCB_set_nd_filter ( lua_State L)
static

Definiert in Zeile 963 der Datei luascript.c.

964 {
966  return 0;
967 }
static int luaCB_set_prop ( lua_State L)
static

Definiert in Zeile 973 der Datei luascript.c.

974 {
976  return 0;
977 }
static int luaCB_set_prop_str ( lua_State L)
static

Definiert in Zeile 985 der Datei luascript.c.

985  {
986  int prop_id;
987  unsigned len;
988  const char *str;
989  prop_id = luaL_checknumber( L, 1 );
990  str = luaL_checklstring( L, 2, &len );
991  if(str && len > 0) {
992  lua_pushboolean( L, (set_property_case(prop_id,(void *)str,len) == 0));
993  } else {
994  return luaL_error( L, "invalid value");
995  }
996  return 1;
997 }
static int luaCB_set_raw ( lua_State L)
static

Definiert in Zeile 1011 der Datei luascript.c.

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

Definiert in Zeile 1876 der Datei luascript.c.

1877 {
1879  return 0;
1880 }
static int luaCB_set_raw_nr ( lua_State L)
static

Definiert in Zeile 999 der Datei luascript.c.

1000 {
1001  conf.raw_nr = luaL_checknumber( L, 1 );
1002  return 0;
1003 }
static int luaCB_set_record ( lua_State L)
static

Definiert in Zeile 2141 der Datei luascript.c.

2142 {
2144  return 0;
2145 }
static int luaCB_set_remote_timing ( lua_State L)
static

Definiert in Zeile 1412 der Datei luascript.c.

1413 {
1414  int val= on_off_value_from_lua_arg(L,1);
1415  if (val > 0 )
1417  else
1419  return 1;
1420 }
static int luaCB_set_sv96 ( lua_State L)
static

Definiert in Zeile 1023 der Datei luascript.c.

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

Definiert in Zeile 1035 der Datei luascript.c.

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

Definiert in Zeile 1029 der Datei luascript.c.

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

Definiert in Zeile 2683 der Datei luascript.c.

2684 {
2686  return 0;
2687 }
static int luaCB_set_user_av96 ( lua_State L)
static

Definiert in Zeile 1053 der Datei luascript.c.

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

Definiert in Zeile 1047 der Datei luascript.c.

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

Definiert in Zeile 1041 der Datei luascript.c.

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

Definiert in Zeile 1071 der Datei luascript.c.

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

Definiert in Zeile 1065 der Datei luascript.c.

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

Definiert in Zeile 1059 der Datei luascript.c.

1060 {
1062  return 0;
1063 }
static int luaCB_set_yield ( lua_State L)
static

Definiert in Zeile 2621 der Datei luascript.c.

static int luaCB_set_zoom ( lua_State L)
static

Definiert in Zeile 1089 der Datei luascript.c.

1090 {
1092  return 0;
1093 }
static int luaCB_set_zoom_rel ( lua_State L)
static

Definiert in Zeile 1083 der Datei luascript.c.

1084 {
1086  return 0;
1087 }
static int luaCB_set_zoom_speed ( lua_State L)
static

Definiert in Zeile 1077 der Datei luascript.c.

1078 {
1080  return 0;
1081 }
static int luaCB_shoot ( lua_State L)
static

Definiert in Zeile 442 der Datei luascript.c.

443 {
444  action_push_shoot(luaL_optnumber( L, 1, 1 ));
445  return lua_yield( L, 0 );
446 }
static int luaCB_shoot_hook_continue ( lua_State L)
static

Definiert in Zeile 2788 der Datei luascript.c.

2789 {
2790  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2792  return 0;
2793 }
static int luaCB_shoot_hook_count ( lua_State L)
static

Definiert in Zeile 2800 der Datei luascript.c.

2801 {
2802  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2804  return 1;
2805 }
static int luaCB_shoot_hook_is_ready ( lua_State L)
static

Definiert in Zeile 2777 der Datei luascript.c.

2778 {
2779  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2781  return 1;
2782 }
static int luaCB_shoot_hook_set ( lua_State L)
static

Definiert in Zeile 2766 der Datei luascript.c.

2767 {
2768  int hook = lua_tonumber( L, lua_upvalueindex(1) );
2770  return 0;
2771 }
static int luaCB_shot_histo_enable ( lua_State L)
static

Definiert in Zeile 1611 der Datei luascript.c.

1612 {
1614  return 0;
1615 }
static int luaCB_shot_histo_write_to_file ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 1617 der Datei luascript.c.

1618 {
1620  return 0;
1621 }
static int luaCB_shut_down ( lua_State L)
static

Definiert in Zeile 1463 der Datei luascript.c.

1464 {
1465  if ( luaL_optnumber(L,1,0) == 1 )
1466  {
1467  shutdown();
1468  } else {
1470  }
1471  return 0;
1472 }
static int luaCB_sleep ( lua_State L)
static

Definiert in Zeile 471 der Datei luascript.c.

472 {
473  int delay = sleep_delay(luaL_checknumber( L, 1 ));
474 
475  if (delay > 0)
476  {
477  action_push(delay);
479  }
480 
481  return lua_yield( L, 0 );
482 }
static int luaCB_sv96_market_to_real ( lua_State L)
static

Definiert in Zeile 2722 der Datei luascript.c.

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

Definiert in Zeile 2716 der Datei luascript.c.

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

Definiert in Zeile 2698 der Datei luascript.c.

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

Definiert in Zeile 530 der Datei luascript.c.

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

Definiert in Zeile 2149 der Datei luascript.c.

2150 {
2152  return 0;
2153 }
static int luaCB_textbox ( lua_State L)
static

Definiert in Zeile 1264 der Datei luascript.c.

1264  {
1265  // Disconnect button input from script so buttons will work in the textbox
1267  // Switch to textbox gui mode. Text box prompt should be passed as param.
1268  int rv = libtextbox->textbox_init((int)luaL_optstring( L, 1, "Text box" ), //title
1269  (int)luaL_optstring( L, 2, "Enter text" ), //message
1270  luaL_optstring( L, 3, "" ), //default string
1271  luaL_optnumber( L, 4, 30), //max size of a text
1273  if (rv)
1274  {
1275  // Push textbox action onto stack - will loop doing nothing until textbox exits
1277  }
1278  else
1280 
1281  // Yield the script so that the action stack will process the AS_TEXTBOX action
1282  return lua_yield(L, 0);
1283 }
static int luaCB_tv96_to_usec ( lua_State L)
static

Definiert in Zeile 2746 der Datei luascript.c.

2747 {
2748  lua_pushnumber(L, (int)(shooting_get_shutter_speed_from_tv96(luaL_checknumber(L, 1)) * 1000000.0 + 0.5));
2749  return 1;
2750 }
static int luaCB_usb_force_active ( lua_State L)
static

Definiert in Zeile 1423 der Datei luascript.c.

1424 {
1426  return 1;
1427 }
static int luaCB_usb_sync_wait ( lua_State L)
static

Definiert in Zeile 1430 der Datei luascript.c.

1431 {
1433  return 0;
1434 }
static int luaCB_usec_to_tv96 ( lua_State L)
static

Definiert in Zeile 2740 der Datei luascript.c.

2741 {
2743  return 1;
2744 }
static int luaCB_wait_click ( lua_State L)
static

Definiert in Zeile 1114 der Datei luascript.c.

1115 {
1116  int delay = luaL_optnumber( L, 1, 0 );
1117  if (delay == 0) delay = -1;
1118  delay = sleep_delay(delay);
1119 
1120  // Reset 'clicked' key if it has not changed since last time
1122  {
1124  }
1125 
1126  // Set up for wait or click testing
1127  action_push(delay);
1129 
1130  // Check for short delay or key already pressed by calling action stack routine once now
1131  if (action_stack_AS_LUA_WAIT_CLICK() == 0)
1132  {
1133  return lua_yield( L, 0 );
1134  }
1135 
1136  return 0;
1137 }
static int luaCB_wheel_left ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 1164 der Datei luascript.c.

1165 {
1166  JogDial_CCW();
1167  return 0;
1168 }
static int luaCB_wheel_right ( __attribute__((unused)) lua_State L)
static

Definiert in Zeile 1158 der Datei luascript.c.

1159 {
1160  JogDial_CW();
1161  return 0;
1162 }
static int luaCB_write_usb_msg ( lua_State L)
static

Definiert in Zeile 2496 der Datei luascript.c.

2497 {
2498  ptp_script_msg *msg;
2499  int timeout = sleep_delay(luaL_optnumber(L,2,0));
2500  // TODO would it be better to either ignore this or return nil ?
2501  // a write_usb_msg(function_which_returns_no_value()) is an error in this case
2502  // replacing with nil might be more luaish
2503  if (lua_gettop(L) < 1)
2504  {
2505  return luaL_error(L,"missing argument");
2506  }
2508  // for user messages, trying to create a message from an incompatible type throws an error
2509  if (msg->subtype == PTP_CHDK_TYPE_UNSUPPORTED)
2510  {
2511  free(msg);
2512  return luaL_error(L,"unsupported type");
2513  }
2514  if (!msg)
2515  {
2516  return luaL_error(L,"failed to create message");
2517  }
2518  if (timeout)
2519  {
2520  action_push(timeout);
2521  action_push((int)msg);
2523  return lua_yield( L, 0 );
2524  }
2526  return 1;
2527 }
static unsigned on_off_value_from_lua_arg ( lua_State L,
int  index 
)
static

Definiert in Zeile 375 der Datei luascript.c.

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

Definiert in Zeile 2176 der Datei luascript.c.

2177 {
2178  unsigned i;
2179  unsigned end = lua_gettop(L);
2180 
2181  for(i = start; i <= end; i++,argbuf++) {
2182  if (lua_type(L, i) == LUA_TSTRING) {
2183  *argbuf=(unsigned)lua_tostring( L, i);
2184  }
2185  else if (lua_type(L, i) == LUA_TNUMBER) {
2186  *argbuf=lua_tonumber( L, i);
2187  }
2188  else {
2189  return 0;
2190  }
2191  }
2192  return 1;
2193 }
void register_lua_funcs ( lua_State L)

Definiert in Zeile 3059 der Datei luascript.c.

3060 {
3061  const luaL_reg *r;
3062 
3063  register_shoot_hooks( L );
3064  luaopen_rawop( L );
3065 
3068  lua_setglobal( L, "click" );
3069 
3072  lua_setglobal( L, "press" );
3073 
3076  lua_setglobal( L, "release" );
3077 
3078  for(r=chdk_funcs;r->name;r++) {
3079  lua_pushcfunction( L, r->func );
3080  lua_setglobal( L, r->name );
3081  }
3082  (void)luaL_dostring(L,"function usb_msg_table_to_string(t)"
3083  " local v2s=function(v)"
3084  " local t=type(v)"
3085  " if t=='string' then return v end"
3086  " if t=='number' or t=='boolean' or t=='nil' then return tostring(v) end"
3087  " return '' end"
3088  " local r=''"
3089  " for k,v in pairs(t) do"
3090  " local s,vs=''"
3091  " if type(v)=='table' then"
3092  " for i=1,table.maxn(v) do"
3093  " s=s..'\\t'..v2s(v[i]) end"
3094  " else"
3095  " vs=v2s(v)"
3096  " if #vs then s=s..'\\t'..vs end"
3097  " end"
3098  " vs=v2s(k)"
3099  " if #vs>0 and #s>0 then r=r..vs..s..'\\n' end"
3100  " end"
3101  " return r"
3102  " end");
3103 
3104 }
void register_shoot_hook_fn ( lua_State L,
int  hook,
void *  hook_fn,
const char *  name 
)

Definiert in Zeile 3038 der Datei luascript.c.

3039 {
3040  lua_pushnumber( L, hook );
3041  lua_pushcclosure( L, hook_fn, 1 );
3042  lua_setfield( L, -2, name);
3043 }
void register_shoot_hooks ( lua_State L)

Definiert in Zeile 3045 der Datei luascript.c.

3046 {
3047  int i;
3048  for(i=0; i<SCRIPT_NUM_SHOOT_HOOKS;i++) {
3049  lua_createtable(L, 0, 4);
3051 // register_shoot_hook_fn(L,i,luaCB_shoot_hook_wait_ready,"wait_ready");
3056  }
3057 }
static void return_string_selected ( const char *  str)
static

Definiert in Zeile 1231 der Datei luascript.c.

1231  {
1232  // Reconnect button input to script - will also signal action stack
1233  // that file browser / textbox is finished and return last selected file
1234  // to script caller
1236 
1237  // Push selected file as script return value
1238  lua_pushstring( Lt, (str && str[0])? str : NULL );
1239 }
static void set_meminfo_num ( lua_State L,
const char *  name,
int  val 
)
static

Definiert in Zeile 2530 der Datei luascript.c.

2530  {
2531  if(val != -1) {
2532  set_number_field( L, name, val );
2533  }
2534 }
void set_number_field ( lua_State L,
const char *  key,
int  val 
)

Definiert in Zeile 1845 der Datei luascript.c.

1846 {
1847  lua_pushnumber(L, val);
1848  lua_setfield(L, -2, key);
1849 }
void set_string_field ( lua_State L,
const char *  key,
const char *  val 
)

Definiert in Zeile 1839 der Datei luascript.c.

1840 {
1841  lua_pushstring(L, val);
1842  lua_setfield(L, -2, key);
1843 }
static int sleep_delay ( int  delay)
static

Definiert in Zeile 459 der Datei luascript.c.

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

Variablen-Dokumentation

const luaL_Reg chdk_funcs[]
static

Definiert in Zeile 2810 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.

unsigned 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.