start to do better error-handling
Getty Ritter
1 year, 11 months ago
145 | 145 | [ "Lua definition of `telml.", |
146 | 146 | Text.unpack (nafName naf), |
147 | 147 | "` not a function, found ", |
148 |
|
|
148 | ppType (nafActual naf), | |
149 | 149 | " instead" |
150 | 150 | ] |
151 | 151 | where |
152 | go Lua.TypeNil = "nil" | |
153 | go Lua.TypeBoolean = "boolean" | |
154 | go Lua.TypeLightUserdata = "userdata (light)" | |
155 | go Lua.TypeNumber = "number" | |
156 | go Lua.TypeString = "string" | |
157 | go Lua.TypeTable = "table" | |
158 | go Lua.TypeFunction = "function" | |
159 | go Lua.TypeUserdata = "userdata" | |
160 | go Lua.TypeThread = "thread" | |
161 | go Lua.TypeNone = "something unspeakable" | |
152 | ||
153 | data NotAString = NotAString | |
154 | {nasName :: Text.Text, nasActual :: Lua.Type} | |
155 | deriving (Show) | |
156 | ||
157 | instance Exn.Exception NotAString where | |
158 | displayException nas = | |
159 | concat | |
160 | [ "Result of calling `telml.", | |
161 | Text.unpack (nasName nas), | |
162 | "` not a string, found ", | |
163 | ppType (nasActual nas), | |
164 | " instead" | |
165 | ] | |
166 | where | |
167 | ||
168 | ppType :: Lua.Type -> String | |
169 | ppType Lua.TypeNil = "nil" | |
170 | ppType Lua.TypeBoolean = "boolean" | |
171 | ppType Lua.TypeLightUserdata = "userdata (light)" | |
172 | ppType Lua.TypeNumber = "number" | |
173 | ppType Lua.TypeString = "string" | |
174 | ppType Lua.TypeTable = "table" | |
175 | ppType Lua.TypeFunction = "function" | |
176 | ppType Lua.TypeUserdata = "userdata" | |
177 | ppType Lua.TypeThread = "thread" | |
178 | ppType Lua.TypeNone = "something unspeakable" | |
162 | 179 | |
163 | 180 | standardTags :: Text.Text -> [Text.Text] -> LuaM Text.Text |
164 | 181 | standardTags n ps = |
195 | 212 | case result of |
196 | 213 | Nothing -> do |
197 | 214 | actualtyp <- Lua.ltype 2 |
198 |
|
|
215 | throw (NotAString n actualtyp) | |
199 | 216 | Just r -> do |
200 | 217 | return (Text.decodeUtf8 r) |
201 | 218 | _ -> throw (NotAFunction n typ) |