| 1077 | } |
| 1078 | |
| 1079 | static bool doAssignDFObject(color_ostream *out, lua_State *state, |
| 1080 | const type_identity *type, void *target, int val_index, |
| 1081 | bool exact, bool perr, bool signal) |
| 1082 | { |
| 1083 | if (signal) |
| 1084 | check_valid_ptr_index(state, val_index); |
| 1085 | |
| 1086 | if (lua_istable(state, val_index)) |
| 1087 | { |
| 1088 | val_index = lua_absindex(state, val_index); |
| 1089 | lua_getfield(state, LUA_REGISTRYINDEX, DFHACK_ASSIGN_NAME); |
| 1090 | Lua::PushDFObject(state, type, target); |
| 1091 | lua_pushvalue(state, val_index); |
| 1092 | |
| 1093 | if (signal) |
| 1094 | { |
| 1095 | lua_call(state, 2, 0); |
| 1096 | return true; |
| 1097 | } |
| 1098 | else |
| 1099 | return Lua::SafeCall(*out, state, 2, 0, perr); |
| 1100 | } |
| 1101 | else if (!lua_isuserdata(state, val_index)) |
| 1102 | { |
| 1103 | signal_typeid_error(out, state, type, "pointer to {} expected", |
| 1104 | val_index, perr, signal); |
| 1105 | return false; |
| 1106 | } |
| 1107 | else |
| 1108 | { |
| 1109 | void *in_ptr = Lua::GetDFObject(state, type, val_index, exact); |
| 1110 | if (!in_ptr) |
| 1111 | { |
| 1112 | signal_typeid_error(out, state, type, "incompatible pointer type: {} expected", |
| 1113 | val_index, perr, signal); |
| 1114 | return false; |
| 1115 | } |
| 1116 | if (!type->copy(target, in_ptr)) |
| 1117 | { |
| 1118 | signal_typeid_error(out, state, type, "no copy support for {}", |
| 1119 | val_index, perr, signal); |
| 1120 | return false; |
| 1121 | } |
| 1122 | return true; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | bool DFHack::Lua::AssignDFObject(color_ostream &out, lua_State *state, |
| 1127 | const type_identity *type, void *target, int val_index, |
no test coverage detected