Skip to content

Commit

Permalink
New function added captureError(error_string)
Browse files Browse the repository at this point in the history
  • Loading branch information
AGulev committed Apr 15, 2022
1 parent edb0181 commit 31ee1f7
Show file tree
Hide file tree
Showing 5 changed files with 206 additions and 0 deletions.
161 changes: 161 additions & 0 deletions example/example.gui
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,167 @@ nodes {
text_tracking: 0.0
custom_type: 0
}
nodes {
position {
x: 176.0
y: 143.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEMPLATE
id: "lua-error"
layer: ""
inherit_alpha: true
alpha: 1.0
template: "/dirtylarry/button.gui"
template_node_child: false
custom_type: 0
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 300.0
y: 88.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_BOX
blend_mode: BLEND_MODE_ALPHA
texture: "button/button_normal"
id: "lua-error/larrybutton"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
adjust_mode: ADJUST_MODE_FIT
parent: "lua-error"
layer: ""
inherit_alpha: true
slice9 {
x: 32.0
y: 32.0
z: 32.0
w: 32.0
}
clipping_mode: CLIPPING_MODE_NONE
clipping_visible: true
clipping_inverted: false
alpha: 1.0
template_node_child: true
size_mode: SIZE_MODE_MANUAL
custom_type: 0
}
nodes {
position {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
rotation {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
scale {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
size {
x: 200.0
y: 100.0
z: 0.0
w: 1.0
}
color {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
type: TYPE_TEXT
blend_mode: BLEND_MODE_ALPHA
text: "lua-error"
font: "larryfont"
id: "lua-error/larrylabel"
xanchor: XANCHOR_NONE
yanchor: YANCHOR_NONE
pivot: PIVOT_CENTER
outline {
x: 0.0
y: 0.0
z: 0.0
w: 1.0
}
shadow {
x: 1.0
y: 1.0
z: 1.0
w: 1.0
}
adjust_mode: ADJUST_MODE_FIT
line_break: false
parent: "lua-error/larrybutton"
layer: ""
inherit_alpha: true
alpha: 1.0
outline_alpha: 1.0
shadow_alpha: 1.0
overridden_fields: 8
template_node_child: true
text_leading: 1.0
text_tracking: 0.0
custom_type: 0
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT
max_nodes: 512
22 changes: 22 additions & 0 deletions example/poki-sdk.gui_script
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
local dirtylarry = require "dirtylarry/dirtylarry"

local function setup_error_handling()
if not poki_sdk then
return
end

sys.set_error_handler(function(source, message, traceback)
-- Concatenate all args to make the error string like that:
-- lua: example/poki-sdk.gui_script:86: attempt to index global 'dsf' (a nil value)
-- stack traceback:
-- [C]:-1: in function set_position
-- example/poki-sdk.gui_script:31: in function <example/poki-sdk.gui_script:18>
poki_sdk.capture_error(source .. ": " .. message .. "\n" .. traceback)
end)
end

function init(self)
msg.post(".", "acquire_input_focus")

Expand All @@ -10,6 +25,8 @@ function init(self)
-- poki_sdk.set_debug(engine_info.is_debug)
end
sound.play("#sound")

setup_error_handling()
end

local function on_commercial_break_finished(self)
Expand Down Expand Up @@ -63,6 +80,11 @@ function on_input(self, action_id, action)
local str = "param1:"..tostring(param1).."\nparam2:"..tostring(param2)
gui.set_text(gui.get_node("params"), str)
end)

dirtylarry:button("lua-error", action_id, action, function()
print("Click lua-error")
print(dsf.frt)
end)

end
end
9 changes: 9 additions & 0 deletions poki-sdk/api/poki-sdk.script_api
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
parameters:
- name: is_debug
type: boolean

#*****************************************************************************************************

- name: capture_error
type: function

parameters:
- name: error
type: string

#*****************************************************************************************************

Expand Down
4 changes: 4 additions & 0 deletions poki-sdk/lib/web/lib_pokisdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ var LibPokiSdk = {
PokiSDK.setDebug(value);
},

PokiSdkJs_CaptureError: function(error) {
PokiSDK.captureError(UTF8ToString(error));
},

PokiSdkJs_IsAdBlocked: function() {
return PokiSDK.isAdBlocked();
},
Expand Down
10 changes: 10 additions & 0 deletions poki-sdk/src/pokisdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ extern "C" {
void PokiSdkJs_GameplayStart();
void PokiSdkJs_GameplayStop();
void PokiSdkJs_SetDebug(bool value);
void PokiSdkJs_CaptureError(const char* error);

void PokiSdkJs_CommercialBreak(CommercialBreakCallback callback);
void PokiSdkJs_RewardedBreak(RewardedBreakCallback callback);
Expand Down Expand Up @@ -154,6 +155,14 @@ static int PokiSdk_SetDebug(lua_State* L)
return 0;
}

static int PokiSdk_CaptureError(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 0);
const char* error = luaL_checkstring(L, 1);
PokiSdkJs_CaptureError(error);
return 0;
}

static int PokiSdk_IsAdBlocked(lua_State* L)
{
DM_LUA_STACK_CHECK(L, 1);
Expand Down Expand Up @@ -217,6 +226,7 @@ static const luaL_reg Module_methods[] =
{"commercial_break", PokiSdk_CommercialBreak},
{"rewarded_break", PokiSdk_RewardedBreak},
{"set_debug", PokiSdk_SetDebug},
{"capture_error", PokiSdk_CaptureError},
{"is_ad_blocked", PokiSdk_IsAdBlocked},
{"shareable_url", PokiSdk_ShareableURL},
{"get_url_param", PokiSdk_GetURLParam},
Expand Down

0 comments on commit 31ee1f7

Please sign in to comment.