From 4fe094e39c91ac11b0b34f6288c430e76ea55c62 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 6 Nov 2024 12:21:15 +0300 Subject: [PATCH] Throwing an exception in getters if component is missing --- tpl/bind_ecslite.twig | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/tpl/bind_ecslite.twig b/tpl/bind_ecslite.twig index 6851d9a..0de05e9 100644 --- a/tpl/bind_ecslite.twig +++ b/tpl/bind_ecslite.twig @@ -123,13 +123,15 @@ else {%- endif ~%} { - dv = Val.New(frm.vm); var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>(); if(pool.Has(id)) { + dv = Val.New(frm.vm); var v = pool.Get(id).{{f.name}}; {{ bhl_bind.native2val(f.type, 'v', 'dv') }}; } + else + throw new Exception("No such component '{{token_or(o, 'bhl_native_class', o.name)}}' on entity: " + id); } stack.Push(dv); #endif @@ -162,10 +164,11 @@ var pool = world.GetPool<{{token_or(o, 'bhl_native_class', o.name)}}>(); - {%~ if m.returntype %} if(pool.Has(id)) { + {%~ if m.returntype %} var return_val = + {%- endif ~%} pool.Get(id).{{m.name}}( {%- for arg in m.args ~%} __{{arg.name}}{% if not loop.last %},{% endif %} {%- endfor ~%} @@ -174,18 +177,7 @@ {{ bhl_bind.return_val(m, 'return_val') }} } else - { - //unspecified value - var dv = bhl.Val.New(frm.vm); - stack.Push(dv); - } - {%- else ~%} - - pool.Ensure(id).{{m.name}}( - {%- for arg in m.args ~%} __{{arg.name}}{% if not loop.last %},{% endif %} {%- endfor ~%} - ); - - {%- endif ~%} + throw new Exception("No such component '{{token_or(o, 'bhl_native_class', o.name)}}' on entity: " + id); return null; }