The Sol Programming Language!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

util.c 818B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "sol.h"
  2. #include <stdarg.h>
  3. sol_object_t *sol_util_call(sol_state_t *state, sol_object_t *func, int *error, int elems, ...) {
  4. va_list va;
  5. sol_object_t *args = sol_new_list(state), *res = NULL;
  6. int i;
  7. if(sol_has_error(state)) {
  8. return sol_incref(state->None);
  9. }
  10. if(error) {
  11. *error = 0;
  12. }
  13. sol_list_insert(state, args, 0, func);
  14. va_start(va, elems);
  15. for(i = 0; i < elems; i++) {
  16. sol_list_insert(state, args, i + 1, va_arg(va, sol_object_t *));
  17. }
  18. va_end(va);
  19. if(!func->ops->call) {
  20. return sol_incref(state->None);
  21. }
  22. res = func->ops->call(state, args);
  23. if(!res) {
  24. res = sol_incref(state->None);
  25. }
  26. if(sol_has_error(state)) {
  27. sol_object_t *err = sol_get_error(state);
  28. sol_clear_error(state);
  29. sol_obj_free(res);
  30. if(error) {
  31. *error = 1;
  32. }
  33. res = err;
  34. }
  35. return res;
  36. }