source: branches/juciphox/lib/lua/lobject.c @ 416

Revision 416, 5.6 KB checked in by Jucifer, 5 years ago (diff)

(pretty much from http://chdk.setepontos.com/index.php/topic,688.0.html:)

  • all uBASIC commands beginning with "get_" can now use the "new" syntax (e.g. [f=]get_focus, S=get_prop 205), the ones listed in Wikia work as they used to

+ applied PhyrePhox?'s customizations (the newest commands have the new syntax ([x=]command)), http://chdk.setepontos.com/index.php/topic,978.msg8339.html#msg8339

+ applied wontolla's RAW purge, http://chdk.setepontos.com/index.php/topic,557.msg5849.html#msg5849

+ applied m2tk's gui_fselect.c-patch, http://chdk.setepontos.com/index.php/topic,1059.msg9530.html#msg9530

+ applied CHDKLover's and msl's Symbol Mod, http://chdk.setepontos.com/index.php/topic,1133.msg10043.html#msg10043

+ applied Velo's Lua Scripting Integration (and added all new uBASIC-commands), http://chdk.setepontos.com/index.php/topic,1194.msg11413.html#msg11413

+ added scripting command get_exp_count (value incremented by 1 on every exposure, returns numbers as in the files saved by the camera (1-9999, should be taken into account when scripting, maybe something along these lines:
T=get_exp_count+N
if T>9999 then T=T-9999
press "shoot_half"
press "shoot_full"
do
until get_exp_count=T
release "shoot_full"
), ubasic syntax: [x=]get_exp_count ([]=optional))

+ added scripting command is_pressed. Usage is similar to is_key, but checks, if a button is pressed, when the command is called. This can be really useful in autostart-scripts.

+ added script command autostarted, returns 1/true if script was autostarted, 0/false if not

  • modified get_script_autostart and set_script_autostart to read & write conf.script_startup (values: 0=off, 1=on, 2=once)
  • new script autostart option(s): Off, On, Once
  • user menu modified
    • now with 14 entries (that's what fits on my screen with the default font)
    • main menu -entry removed
    • invoked also with shoot_half + menu
    • can be used as root menu, main menu becomes accessible with shoot_half + menu
  • faster menu navigation
    • in alt menus and file browser, shoot_half can be used with up/down to move 4 items up/down at a time
    • int-variable changing behaviour is modified: zoom rocker works also a bit like shift: when "held down" while pressing left/right, zoom_out changes values by 10, zoom_in by 100, shoot_half by 1000.
    • int-variables can be set to 0 with shoot_half+set
    • when changing enum-type-variables (e.g. Tv bracketing value), zoom_in(+left/right) changes value by 6 (2EV), zoom_out and(/or) shoot_half by 3 (1EV).

+ added numbers 2, 4 and 5 from cyril42e's modification list, http://chdk.setepontos.com/index.php/topic,1687.msg15345.html#msg15345

+ added scriptless Ricoh & home hacked remote support from SDM 1.70

+ added fbonomi's shot histogram, commands shot_histo_enable 0|1, get_histo_range from to, http://chdk.setepontos.com/index.php/topic,1145.msg13008.html#msg13008

+ added hiker_jon's edge overlay code for testing, may or may not work, http://chdk.setepontos.com/index.php/topic,1192.msg11317.html#msg11317

+ and last and perhaps least, added the missing get_raw_nr to tokenizer.c

I may have forgotten something. Hopefully nothing major, though.

Line 
1/*
2** $Id: lobject.c,v 2.22.1.1 2007/12/27 13:02:25 roberto Exp $
3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h
5*/
6
7#include <ctype.h>
8#include <stdarg.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <string.h>
12
13#define lobject_c
14#define LUA_CORE
15
16#include "lua.h"
17
18#include "ldo.h"
19#include "lmem.h"
20#include "lobject.h"
21#include "lstate.h"
22#include "lstring.h"
23#include "lvm.h"
24
25
26
27const TValue luaO_nilobject_ = {{NULL}, LUA_TNIL};
28
29
30/*
31** converts an integer to a "floating point byte", represented as
32** (eeeeexxx), where the real value is (1xxx) * 2^(eeeee - 1) if
33** eeeee != 0 and (xxx) otherwise.
34*/
35int luaO_int2fb (unsigned int x) {
36  int e = 0;  /* expoent */
37  while (x >= 16) {
38    x = (x+1) >> 1;
39    e++;
40  }
41  if (x < 8) return x;
42  else return ((e+1) << 3) | (cast_int(x) - 8);
43}
44
45
46/* converts back */
47int luaO_fb2int (int x) {
48  int e = (x >> 3) & 31;
49  if (e == 0) return x;
50  else return ((x & 7)+8) << (e - 1);
51}
52
53
54int luaO_log2 (unsigned int x) {
55  static const lu_byte log_2[256] = {
56    0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
57    6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
58    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
59    7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
60    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
61    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
62    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
63    8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
64  };
65  int l = -1;
66  while (x >= 256) { l += 8; x >>= 8; }
67  return l + log_2[x];
68
69}
70
71
72int luaO_rawequalObj (const TValue *t1, const TValue *t2) {
73  if (ttype(t1) != ttype(t2)) return 0;
74  else switch (ttype(t1)) {
75    case LUA_TNIL:
76      return 1;
77    case LUA_TNUMBER:
78      return luai_numeq(nvalue(t1), nvalue(t2));
79    case LUA_TBOOLEAN:
80      return bvalue(t1) == bvalue(t2);  /* boolean true must be 1 !! */
81    case LUA_TLIGHTUSERDATA:
82      return pvalue(t1) == pvalue(t2);
83    default:
84      lua_assert(iscollectable(t1));
85      return gcvalue(t1) == gcvalue(t2);
86  }
87}
88
89
90int luaO_str2d (const char *s, lua_Number *result) {
91  char *endptr;
92  *result = lua_str2number(s, &endptr);
93  if (endptr == s) return 0;  /* conversion failed */
94#if 0
95  if (*endptr == 'x' || *endptr == 'X')  /* maybe an hexadecimal constant? */
96    *result = cast_num(strtoul(s, &endptr, 16));
97#endif
98  if (*endptr == '\0') return 1;  /* most common case */
99  while (isspace(cast(unsigned char, *endptr))) endptr++;
100  if (*endptr != '\0') return 0;  /* invalid trailing characters? */
101  return 1;
102}
103
104
105
106static void pushstr (lua_State *L, const char *str) {
107  setsvalue2s(L, L->top, luaS_new(L, str));
108  incr_top(L);
109}
110
111
112/* this function handles only `%d', `%c', %f, %p, and `%s' formats */
113const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
114  int n = 1;
115  pushstr(L, "");
116  for (;;) {
117    const char *e = strchr(fmt, '%');
118    if (e == NULL) break;
119    setsvalue2s(L, L->top, luaS_newlstr(L, fmt, e-fmt));
120    incr_top(L);
121    switch (*(e+1)) {
122      case 's': {
123        const char *s = va_arg(argp, char *);
124        if (s == NULL) s = "(null)";
125        pushstr(L, s);
126        break;
127      }
128      case 'c': {
129        char buff[2];
130        buff[0] = cast(char, va_arg(argp, int));
131        buff[1] = '\0';
132        pushstr(L, buff);
133        break;
134      }
135      case 'd': {
136        setnvalue(L->top, cast_num(va_arg(argp, int)));
137        incr_top(L);
138        break;
139      }
140      case 'f': {
141        setnvalue(L->top, cast_num(va_arg(argp, l_uacNumber)));
142        incr_top(L);
143        break;
144      }
145      case 'p': {
146        char buff[4*sizeof(void *) + 8]; /* should be enough space for a `%p' */
147        sprintf(buff, "%p", va_arg(argp, void *));
148        pushstr(L, buff);
149        break;
150      }
151      case '%': {
152        pushstr(L, "%");
153        break;
154      }
155      default: {
156        char buff[3];
157        buff[0] = '%';
158        buff[1] = *(e+1);
159        buff[2] = '\0';
160        pushstr(L, buff);
161        break;
162      }
163    }
164    n += 2;
165    fmt = e+2;
166  }
167  pushstr(L, fmt);
168  luaV_concat(L, n+1, cast_int(L->top - L->base) - 1);
169  L->top -= n;
170  return svalue(L->top - 1);
171}
172
173
174const char *luaO_pushfstring (lua_State *L, const char *fmt, ...) {
175  const char *msg;
176  va_list argp;
177  va_start(argp, fmt);
178  msg = luaO_pushvfstring(L, fmt, argp);
179  va_end(argp);
180  return msg;
181}
182
183
184void luaO_chunkid (char *out, const char *source, size_t bufflen) {
185  if (*source == '=') {
186    strncpy(out, source+1, bufflen);  /* remove first char */
187    out[bufflen-1] = '\0';  /* ensures null termination */
188  }
189  else {  /* out = "source", or "...source" */
190    if (*source == '@') {
191      size_t l;
192      source++;  /* skip the `@' */
193      bufflen -= sizeof(" '...' ");
194      l = strlen(source);
195      strcpy(out, "");
196      if (l > bufflen) {
197        source += (l-bufflen);  /* get last part of file name */
198        strcat(out, "...");
199      }
200      strcat(out, source);
201    }
202    else {  /* out = [string "string"] */
203      strcpy(out,"");
204#if 0
205      size_t len = strcspn(source, "\n\r");  /* stop at first newline */
206      bufflen -= sizeof(" [string \"...\"] ");
207      if (len > bufflen) len = bufflen;
208      strcpy(out, "[string \"");
209      if (source[len] != '\0') {  /* must truncate? */
210        strncat(out, source, len);
211        strcat(out, "...");
212      }
213      else
214        strcat(out, source);
215      strcat(out, "\"]");
216#endif
217    }
218  }
219}
Note: See TracBrowser for help on using the repository browser.