runtime/lib_table.c - ktap

Global variables defined

Functions defined

Source code

  1. /*
  2. * lib_table.c - Table library
  3. *
  4. * This file is part of ktap by Jovi Zhangwei.
  5. *
  6. * Copyright (C) 2012-2013 Jovi Zhangwei <jovi.zhangwei@gmail.com>.
  7. *
  8. * ktap is free software; you can redistribute it and/or modify it
  9. * under the terms and conditions of the GNU General Public License,
  10. * version 2, as published by the Free Software Foundation.
  11. *
  12. * ktap is distributed in the hope it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  20. */

  21. #include <linux/ctype.h>
  22. #include <linux/slab.h>
  23. #include <linux/delay.h>
  24. #include <linux/sched.h>
  25. #include "../include/ktap_types.h"
  26. #include "ktap.h"
  27. #include "kp_obj.h"
  28. #include "kp_vm.h"
  29. #include "kp_tab.h"

  30. static int kplib_table_new(ktap_state_t *ks)
  31. {
  32.     int narr = kp_arg_checkoptnumber(ks, 1, 0);
  33.     int nrec = kp_arg_checkoptnumber(ks, 2, 0);
  34.     ktap_tab_t *h;

  35.     h = kp_tab_new_ah(ks, narr, nrec);
  36.     if (!h) {
  37.         set_nil(ks->top);
  38.     } else {
  39.         set_table(ks->top, h);
  40.     }

  41.     incr_top(ks);
  42.     return 1;
  43. }

  44. static const ktap_libfunc_t table_lib_funcs[] = {
  45.     {"new",    kplib_table_new},
  46.     {NULL}
  47. };

  48. int kp_lib_init_table(ktap_state_t *ks)
  49. {
  50.     return kp_vm_register_lib(ks, "table", table_lib_funcs);
  51. }