txlyre 1 zi în urmă
părinte
comite
f7fe28302a
3 a modificat fișierele cu 385 adăugiri și 412 ștergeri
  1. 41 10
      qirt.c
  2. 344 392
      qistd.c
  3. 0 10
      std.qi

+ 41 - 10
qirt.c

@@ -3899,6 +3899,29 @@ qi_value_t *qi_builtin_table_delete(qi_state_t *state, qi_size_t pargc,
   return a;
 }
 
+qi_value_t *qi_builtin_table_get(qi_state_t *state, qi_size_t pargc,
+                                 qi_list_t *pargs) {
+  qi_value_t *a = qi_list_data(pargs, 0);
+  qi_value_t *b = qi_list_data(pargs, 1);
+  qi_value_t *c = pargc >= 3? qi_list_data(pargs, 2): state->nil;
+
+  if (a->type != QI_TABLE)
+    qi_throw_format(state, "expected first argument to be: table, but got: %s",
+                    _qi_type(state, a));
+
+  if (b->type != QI_STRING)
+    b = qi_to_string(state, b);
+
+  LOCKED(a, {
+    qi_value_t *tmp = NULL;
+
+    if ((tmp = qi_table_get(a->value.table.table, b->value.string)))
+      c = tmp;
+  });
+
+  return c;
+}
+
 qi_value_t *qi_builtin_func_call(qi_state_t *state, qi_size_t pargc,
                                  qi_list_t *pargs) {
   qi_value_t *a = qi_list_data(pargs, 0);
@@ -4030,16 +4053,6 @@ qi_value_t *qi_builtin_table(qi_state_t *state, qi_size_t pargc,
   return qi_to_table(state, a);
 }
 
-qi_value_t *qi_pseudomethod_list_push(qi_state_t *state, qi_size_t pargc,
-                                      qi_list_t *pargs) {
-  return qi_builtin_list_push(state, pargc, pargs);
-}
-
-qi_value_t *qi_pseudomethod_list_pop(qi_state_t *state, qi_size_t pargc,
-                                     qi_list_t *pargs) {
-  return qi_builtin_list_pop(state, pargc, pargs);
-}
-
 qi_value_t *qi_pseudomethod_func_call(qi_state_t *state, qi_size_t pargc,
                                       qi_list_t *pargs) {
   return qi_builtin_func_call(state, pargc, pargs);
@@ -4073,6 +4086,21 @@ qi_value_t *qi_pseudomethod_file_rewind(qi_state_t *state, qi_size_t pargc,
   return qi_builtin_fseek(state, 3, new_pargs);
 }
 
+qi_value_t *qi_pseudomethod_list_push(qi_state_t *state, qi_size_t pargc,
+                                      qi_list_t *pargs) {
+  return qi_builtin_list_push(state, pargc, pargs);
+}
+
+qi_value_t *qi_pseudomethod_list_pop(qi_state_t *state, qi_size_t pargc,
+                                     qi_list_t *pargs) {
+  return qi_builtin_list_pop(state, pargc, pargs);
+}
+
+qi_value_t *qi_pseudomethod_table_get(qi_state_t *state, qi_size_t pargc,
+                                      qi_list_t *pargs) {
+  return qi_builtin_table_get(state, pargc, pargs);
+}
+
 #include "qistd.c"
 
 static void qi_state_setup(qi_state_t *state) {
@@ -4213,6 +4241,7 @@ static void qi_state_setup(qi_state_t *state) {
 
   qi_add_builtin(state, "table_copy", 1, qi_builtin_table_copy);
   qi_add_builtin(state, "table_delete", 2, qi_builtin_table_delete);
+  qi_add_builtin(state, "table_get", 2, qi_builtin_table_get);
 
   qi_add_builtin(state, "func_name", 1, qi_builtin_func_name);
   qi_add_builtin(state, "func_argc", 1, qi_builtin_func_argc);
@@ -4237,6 +4266,8 @@ static void qi_state_setup(qi_state_t *state) {
   qi_add_pseudomethod(state, "list.push", 1, qi_pseudomethod_list_push);
   qi_add_pseudomethod(state, "list.pop", 0, qi_pseudomethod_list_pop);
 
+  qi_add_pseudomethod(state, "table.get", 1, qi_pseudomethod_table_get);
+
   qi_add_pseudomethod(state, "function.call", 1, qi_pseudomethod_func_call);
 
   state->_debug_data = NULL;

Fișier diff suprimat deoarece este prea mare
+ 344 - 392
qistd.c


+ 0 - 10
std.qi

@@ -389,16 +389,6 @@ func str_strip(s, cs=" \t\n\r\x0b\x0c") {
   return str_lstrip(str_rstrip(s, cs), cs)
 }
 set_pseudomethod("string.strip", str_strip)
-func table_get(t, k, d=nil) {
-  if type(t) != "table"
-    throw "expected first argument to be: table, but got: " + type(t)
-  if type(k) != "string"
-    throw "expected second argument to be: string, but got: " + type(k)
-  if k !in t
-    return d
-  return t[k]
-}
-set_pseudomethod("table.get", table_get)
 func zip() {
   if !arguments
     return []

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff