| 181 | } |
| 182 | |
| 183 | int type_format(lua_State *L) { |
| 184 | int top = lua_gettop(L); |
| 185 | |
| 186 | if (top < 4) { |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | if (lua_isstring(L, 1) && lua_isstring(L, 2) && lua_isinteger(L, 3) && lua_isinteger(L, 4)) { |
| 191 | try { |
| 192 | std::string filename = lua_tostring(L, 1); |
| 193 | std::string text = lua_tostring(L, 2); |
| 194 | auto line = lua_tointeger(L, 3); |
| 195 | auto character = lua_tointeger(L, 4); |
| 196 | |
| 197 | if (line < 0 || character < 0) { |
| 198 | lua_pushboolean(L, false); |
| 199 | lua_pushstring(L, "line or character param error"); |
| 200 | return 2; |
| 201 | } |
| 202 | |
| 203 | LuaCodeFormat::ConfigMap configMap; |
| 204 | |
| 205 | if (top == 5 && lua_istable(L, 5)) { |
| 206 | lua_pushnil(L); |
| 207 | while (lua_next(L, -2) != 0) { |
| 208 | auto key = luaToString(L, -2); |
| 209 | auto value = luaToString(L, -1); |
| 210 | |
| 211 | if (key != "nil") { |
| 212 | configMap.insert({key, value}); |
| 213 | } |
| 214 | |
| 215 | lua_pop(L, 1); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | LuaCodeFormat::ConfigMap stringTypeOptions; |
| 220 | if (top == 6 && lua_istable(L, 6)) { |
| 221 | lua_pushnil(L); |
| 222 | while (lua_next(L, -2) != 0) { |
| 223 | auto key = luaToString(L, -2); |
| 224 | auto value = luaToString(L, -1); |
| 225 | |
| 226 | if (key != "nil") { |
| 227 | stringTypeOptions.insert({key, value}); |
| 228 | } |
| 229 | |
| 230 | lua_pop(L, 1); |
| 231 | } |
| 232 | } |
| 233 | auto typeFormatResult = LuaCodeFormat::GetInstance() |
| 234 | .TypeFormat(filename, |
| 235 | static_cast<std::size_t>(line), static_cast<std::size_t>(character), |
| 236 | std::move(text), configMap, stringTypeOptions); |
| 237 | |
| 238 | if (typeFormatResult.Type == ResultType::Err) { |
| 239 | lua_pushboolean(L, false); |
| 240 | return 1; |
nothing calls this directly
no test coverage detected