| 6830 | } |
| 6831 | |
| 6832 | static int emit_result(Lua L, long long *sprc, char **err) |
| 6833 | { |
| 6834 | const char *retstr = NULL; |
| 6835 | dbtable_t *rettab = NULL; |
| 6836 | long long retnum = 0; |
| 6837 | int retargs = lua_gettop(L); |
| 6838 | for (int i = 1; i <= retargs; ++i) { |
| 6839 | switch (luabb_dbtype(L, i)) { |
| 6840 | case DBTYPES_LSTRING: |
| 6841 | case DBTYPES_CSTRING: retstr = luabb_tostring(L, i); break; |
| 6842 | case DBTYPES_LNUMBER: |
| 6843 | case DBTYPES_INTEGER: luabb_tointeger(L, i, &retnum); break; |
| 6844 | case DBTYPES_DBTABLE: rettab = lua_touserdata(L, i); break; |
| 6845 | default: |
| 6846 | // TODO FIXME XXX: silently ignore other types?? |
| 6847 | break; |
| 6848 | } |
| 6849 | } |
| 6850 | // lua_settop(L, 0); -- not necessary, right?? |
| 6851 | |
| 6852 | if (rettab) dbtable_emit_int(L, rettab); |
| 6853 | |
| 6854 | if (retnum && (retnum < -299 || retnum > -200)) retnum = -200; |
| 6855 | *sprc = retnum; |
| 6856 | |
| 6857 | if (retstr) retstr = strdup(retstr); |
| 6858 | *err = (char *)retstr; |
| 6859 | |
| 6860 | return 0; |
| 6861 | } |
| 6862 | |
| 6863 | struct sp_state { |
| 6864 | SP sp; |
no test coverage detected