| 91 | } |
| 92 | |
| 93 | void* ScriptArgs::ptrAt(int i, bool allowNull) const |
| 94 | { |
| 95 | struct Value* value = at(i); |
| 96 | // Every pointer parameter — char*, char**, int*, struct directory*, |
| 97 | // struct JSON* — arrives as TypePointer; picoc allocates the argument slot |
| 98 | // from the prototype, so an array argument has already decayed by here. |
| 99 | if (value->Typ == nullptr || value->Typ->Base != TypePointer) { |
| 100 | fail("argument %d is declared %s, read as a pointer", i + 1, value->Typ != nullptr ? baseName(value->Typ->Base) : "untyped"); |
| 101 | } |
| 102 | void* ptr = value->Val->Pointer; |
| 103 | if (ptr == nullptr && !allowNull) { |
| 104 | fail("argument %d must not be NULL", i + 1); |
| 105 | } |
| 106 | return ptr; |
| 107 | } |
| 108 | |
| 109 | /* ---- integers ---------------------------------------------------------- */ |
| 110 | |