Skip to content

Commit

Permalink
Bump submodule versions (handle new return codes from umka)
Browse files Browse the repository at this point in the history
Signed-off-by: Marek Maškarinec <[email protected]>
  • Loading branch information
marekmaskarinec committed Feb 18, 2024
1 parent 9f6c13a commit 5f3c2c9
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 30 deletions.
4 changes: 2 additions & 2 deletions examples/pomodoro/main.um
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ fn guiPopRect(gui: ^Gui) {
}

if len(gui.rectStack) == 0 {
error("Gui rectangle stack is empty!\n")
exit(1, "Gui rectangle stack is empty!\n")
}
gui.rectStack = delete(gui.rectStack, len(gui.rectStack)-1)
}

fn guiGetLastRect(gui: ^Gui): ^BoundRect {
if len(gui.rectStack) == 0 {
error("Gui rectangle stack is empty!\n")
exit(1, "Gui rectangle stack is empty!\n")
}
return &gui.rectStack[len(gui.rectStack)-1]
}
Expand Down
4 changes: 2 additions & 2 deletions examples/tetris/bag.um
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ fn (b: ^Bag) nextPiece*() {
if b.index == 6 {
b.pieces = slice(b.pieces, 7)
if len(b.pieces) != 7 {
error(sprintf("ASSERT FAIL. %d", len(b.pieces)))
exit(1, sprintf("ASSERT FAIL. %d", len(b.pieces)))
}
b.pieces = append(b.pieces, makeBag())
b.index = 0
} else {
b.index += 1
}
if np != b.getCurrentPiece() {
error("ASSERT FAIL.")
exit(1, "ASSERT FAIL.")
}
}
2 changes: 1 addition & 1 deletion lib/stb
Submodule stb updated 1 files
+74 −34 stb_image_resize2.h
2 changes: 1 addition & 1 deletion main.um
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn init*() {

loadedFont = font.load("etc/roboto.ttf", 16, 2)
if !loadedFont.validate() {
error("could not load font")
exit(1, "could not load font")
}

logo = image.load("etc/logo/logo-normal-white.png")
Expand Down
4 changes: 3 additions & 1 deletion src/misc.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>

#include "tophat.h"

Expand Down Expand Up @@ -99,7 +100,8 @@ th_vector_normalize(float *x, float *y)
}

// implemented in umka_common.c
bool moduleRegularizePath(const char *path, const char *curFolder, char *regularizedPath, int size);
bool
moduleRegularizePath(const char *path, const char *curFolder, char *regularizedPath, int size);

void
th_regularize_path(const char *path, const char *cur_folder, char *regularized_path, int size)
Expand Down
21 changes: 13 additions & 8 deletions src/staembed.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "tophat.h"
#include "tophat.h"
const char *th_em_modulesrc[] = {
"\n"
"import (\n"
Expand Down Expand Up @@ -754,14 +754,17 @@ const char *th_em_modulesrc[] = {
"//~~\n"
"\tif !i.validate() {\n"
"\t\tth.__error(\"image is invalid\")\n"
"\t\treturn\n"
"\t}\t\n"
"\n"
"\tif dm.x * dm.y != len(data) {\n"
"\t\terror(sprintf(\"setData: incorrect dimensions: %v\" + \"!= %v\", dm.x * dm.y, len(data)))\n"
"\t\tth.__error(sprintf(\"setData: incorrect dimensions: %v\" + \"!= %v\", dm.x * dm.y, len(data)))\n"
"\t\treturn\n"
"\t}\n"
"\n"
"\tif len(data) == 0 {\n"
"\t\terror(\"setData: can\'t set empty image\")\n"
"\t\tth.__error(\"setData: can\'t set empty image\")\n"
"\t\treturn\n"
"\t}\n"
"\n"
"\tumth_image_update_data(i^, &data[0], dm)\n"
Expand Down Expand Up @@ -1523,7 +1526,7 @@ const char *th_em_modulesrc[] = {
"fn (t: ^Tilemap) autotile*(src, tileCfg: []th.uu, tile: th.uu) {\n"
"//~~\n"
"\tif len(tileCfg) < 16 {\n"
"\t\terror(\"autotile: tileCfg len isn\'t 16\'\")\n"
"\t\tth.__error(\"autotile: tileCfg len isn\'t 16\'\")\n"
"\t}\n"
"\n"
"\tumth_tilemap_autotile(&t.cells[0], t.w, len(t.cells)/t.w, &src[0], &tileCfg[0], tile)\n"
Expand Down Expand Up @@ -2343,12 +2346,12 @@ const char *th_em_modulesrc[] = {
"}\n"
"\n"
"//~~var enableErrrors\n"
"// If true, errors will result in a call to error(), otherwise printf is used.\n"
"// If true, errors will result in a call to exit(255), otherwise printf is used.\n"
"var enableErrors*: bool = true\n"
"//~~\n"
"fn __error*(msg: str) {\n"
"\tif enableErrors {\n"
"\t\terror(msg)\n"
"\t\texit(255, msg)\n"
"\t} else {\n"
"\t\tprintf(\"error: %s\\n\", msg)\n"
"\t}\n"
Expand Down Expand Up @@ -3326,7 +3329,7 @@ const char *th_em_modulesrc[] = {
"\t\tb.grow = cfg.dimension\n"
"\tcase BoxGrowSubdivision:\n"
"\t\tif cfg.subdivisions == 0 {\n"
"\t\t\terror(\"Invalid subdivision count\")\n"
"\t\t\tth.__error(\"Invalid subdivision count\")\n"
"\t\t}\n"
"\n"
"\t\tb.grow = dm / cfg.subdivisions\n"
Expand Down Expand Up @@ -3612,6 +3615,7 @@ const char *th_em_modulesrc[] = {
"// * multiline\n"
"// * copy paste (now implemented but in a limited way due to the lack of selection)\n"
"// * common input shortcuts\n"
"// - ctrl+delete / ctrl+backspace (delete word)\n"
"fn (gui: ^Gui) textBox*(tb: ^TextBox, cfg: TextBoxConfig = {}) {\n"
"//~~\n"
"\tgui.idx++\n"
Expand Down Expand Up @@ -5823,7 +5827,7 @@ const char *th_em_moduledocs[] = {
"var enableErrors*: bool = true\n"
"```\n"
"\n"
"If true, errors will result in a call to error(), otherwise printf is used.\n"
"If true, errors will result in a call to exit(255), otherwise printf is used.\n"
"\n"
"\n"
"## Color constants\n"
Expand Down Expand Up @@ -6902,6 +6906,7 @@ const char *th_em_moduledocs[] = {
"* multiline\n"
"* copy paste (now implemented but in a limited way due to the lack of selection)\n"
"* common input shortcuts\n"
"- ctrl+delete / ctrl+backspace (delete word)\n"
"\n"
"\n"
"## struct ImageConfig\n"
Expand Down
8 changes: 5 additions & 3 deletions src/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ init()
th_image_init();

UmkaStackSlot s;
if (!umkaCall(
thg->umka, umkaGetFunc(thg->umka, "tophat_main.um", "__th_init"), 0, &s, &s)) {
int res =
umkaCall(thg->umka, umkaGetFunc(thg->umka, "tophat_main.um", "__th_init"), 0, &s, &s);
if (res != 0) {
th_print_umka_error_and_quit();
}
}
Expand Down Expand Up @@ -85,7 +86,8 @@ frame()
if (thg->umth_frame_callback != -1) {
s.realVal = sapp_frame_duration();

if (!umkaCall(thg->umka, thg->umth_frame_callback, 1, &s, &s)) {
int res = umkaCall(thg->umka, thg->umth_frame_callback, 1, &s, &s);
if (res != 0) {
th_print_umka_error_and_quit();
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/allt.um
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ import (
"window.um"
)

fn init*() {}
fn init*() {
}
1 change: 0 additions & 1 deletion tests/canvast.um
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var (
)

fn init*() {
exit()
img = image.load("etc/test.png")
window.setViewport(th.Vf2{192, 168})

Expand Down
2 changes: 1 addition & 1 deletion tests/dpit.um
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn init*() {
window.setViewport(window.getDims())
f = font.load("etc/roboto.ttf", 64, 1)
if f.validate() == false {
error("Invalid font.");
exit(1, "Invalid font.");
}

dpiEnabled = window.isDpiEnabled()
Expand Down
2 changes: 1 addition & 1 deletion tests/fontt.um
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn init*() {
window.setViewport(th.Vf2{400, 400})
f = font.load("etc/roboto.ttf", 16, 0)
if f.validate() == false {
error("Invalid font.");
exit(1, "Invalid font.");
}

window.onFrame.register(signal.Callback{
Expand Down
7 changes: 5 additions & 2 deletions umka/image.um
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,17 @@ fn (i: ^Image) setData*(data: []uint32, dm: th.Vf2) {
//~~
if !i.validate() {
th.__error("image is invalid")
return
}

if dm.x * dm.y != len(data) {
error(sprintf("setData: incorrect dimensions: %v" + "!= %v", dm.x * dm.y, len(data)))
th.__error(sprintf("setData: incorrect dimensions: %v" + "!= %v", dm.x * dm.y, len(data)))
return
}

if len(data) == 0 {
error("setData: can't set empty image")
th.__error("setData: can't set empty image")
return
}

umth_image_update_data(i^, &data[0], dm)
Expand Down
4 changes: 2 additions & 2 deletions umka/th.um
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,12 @@ fn getFuncs*(): ^struct{} {
}

//~~var enableErrrors
// If true, errors will result in a call to error(), otherwise printf is used.
// If true, errors will result in a call to exit(255), otherwise printf is used.
var enableErrors*: bool = true
//~~
fn __error*(msg: str) {
if enableErrors {
error(msg)
exit(255, msg)
} else {
printf("error: %s\n", msg)
}
Expand Down
2 changes: 1 addition & 1 deletion umka/tilemap.um
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn umth_tilemap_autotile(tgt: ^th.uu, w, h: th.uu, src, cfg: ^th.uu, tile: th.uu
fn (t: ^Tilemap) autotile*(src, tileCfg: []th.uu, tile: th.uu) {
//~~
if len(tileCfg) < 16 {
error("autotile: tileCfg len isn't 16'")
th.__error("autotile: tileCfg len isn't 16'")
}

umth_tilemap_autotile(&t.cells[0], t.w, len(t.cells)/t.w, &src[0], &tileCfg[0], tile)
Expand Down
2 changes: 1 addition & 1 deletion umka/ui.um
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ fn (gui: ^Gui) box*(cfg: BoxConfig = {
b.grow = cfg.dimension
case BoxGrowSubdivision:
if cfg.subdivisions == 0 {
error("Invalid subdivision count")
th.__error("Invalid subdivision count")
}

b.grow = dm / cfg.subdivisions
Expand Down

0 comments on commit 5f3c2c9

Please sign in to comment.