@@ -23088,6 +23088,7 @@ typedef struct LuaCEmbed{
23088
23088
int lib_identifier;
23089
23089
int stack_leve;
23090
23090
char *main_lib_table;
23091
+ bool field_protection;
23091
23092
}LuaCEmbed;
23092
23093
23093
23094
@@ -23124,6 +23125,7 @@ bool LuaCEmbed_has_errors(LuaCEmbed *self);
23124
23125
23125
23126
void LuaCEmbed_clear_errors(LuaCEmbed *self);
23126
23127
23128
+ void privateLuaCEmbd_get_field_protected(LuaCEmbed *self,const char *name);
23127
23129
23128
23130
void privateLuaCEmbed_raise_error_not_jumping(LuaCEmbed *self, const char *error, ...);
23129
23131
@@ -24117,6 +24119,11 @@ void privata_LuaCEmbed_decrement_stack(LuaCEmbed *self){
24117
24119
24118
24120
}
24119
24121
24122
+ void privateLuaCEmbd_get_field_protected(LuaCEmbed *self,const char *name){
24123
+ self->field_protection = true;
24124
+ lua_getfield(self->state,-1,name);
24125
+ self->field_protection = false;
24126
+ }
24120
24127
24121
24128
void LuaCEmbed_free(LuaCEmbed *self){
24122
24129
privateLuaCEmbedTableArray_free((privateLuaCEmbedTableArray*)self->global_tables);
@@ -24862,33 +24869,14 @@ bool LuaCEmbedTable_get_bool_by_index(LuaCEmbedTable *self, int index){
24862
24869
24863
24870
int LuaCEmbedTable_get_type_prop(LuaCEmbedTable *self, const char *name){
24864
24871
PRIVATE_LUA_CEMBED_TABLE_PROTECT_NUM
24865
- private_lua_cembed_memory_limit = self->main_object->memory_limit;
24866
- lua_getglobal(self->main_object->state,self->global_name);
24867
- int table_index = lua_gettop(self->main_object->state);
24868
-
24869
- lua_pushnil(self->main_object->state);
24870
- while(lua_next(self->main_object->state,table_index)){
24871
-
24872
- bool has_key =lua_type(self->main_object->state,-2) == LUA_CEMBED_STRING;
24873
- if(!has_key){
24874
- lua_pop(self->main_object->state,1);
24875
- continue;
24876
- }
24877
- char* key = (char*)lua_tostring(self->main_object->state,-2);
24872
+ lua_settop(self->main_object->state,0);
24878
24873
24879
- if(strcmp(key,name) != 0){
24880
- lua_pop(self->main_object->state,1);
24881
- continue;
24882
- }
24874
+ private_lua_cembed_memory_limit = self->main_object->memory_limit;
24883
24875
24884
- int type = lua_type(self->main_object->state,-1);
24885
- lua_pop(self->main_object->state,1);
24886
- PRIVATE_LUA_CEMBED_CLEAR_STACK
24887
- return type;
24888
- }
24876
+ lua_getglobal(self->main_object->state,self->global_name);
24877
+ privateLuaCEmbd_get_field_protected(self->main_object,name);
24878
+ return lua_type(self->main_object->state,-1);
24889
24879
24890
- PRIVATE_LUA_CEMBED_CLEAR_STACK
24891
- return LUA_CEMBED_NIL;
24892
24880
}
24893
24881
24894
24882
char* LuaCembedTable_get_string_prop(LuaCEmbedTable *self , const char *name){
@@ -24899,8 +24887,7 @@ char* LuaCembedTable_get_string_prop(LuaCEmbedTable *self , const char *name){
24899
24887
24900
24888
24901
24889
lua_getglobal(self->main_object->state,self->global_name);
24902
- lua_pushstring(self->main_object->state, name);
24903
- lua_gettable(self->main_object->state, -2);
24890
+ privateLuaCEmbd_get_field_protected(self->main_object,name);
24904
24891
if(privateLuaCEmbedTable_ensure_type_with_key(self, name, LUA_CEMBED_STRING)){
24905
24892
return NULL;
24906
24893
}
@@ -24917,8 +24904,7 @@ long long LuaCembedTable_get_long_prop(LuaCEmbedTable *self , const char *name
24917
24904
24918
24905
private_lua_cembed_memory_limit = self->main_object->memory_limit;
24919
24906
lua_getglobal(self->main_object->state,self->global_name);
24920
- lua_pushstring(self->main_object->state, name);
24921
- lua_gettable(self->main_object->state, -2);
24907
+ privateLuaCEmbd_get_field_protected(self->main_object,name);
24922
24908
if(privateLuaCEmbedTable_ensure_type_with_key(self, name, LUA_CEMBED_NUMBER)){
24923
24909
return LUA_CEMBED_GENERIC_ERROR;
24924
24910
}
@@ -24935,8 +24921,8 @@ double LuaCembedTable_get_double_prop(LuaCEmbedTable *self , const char *name){
24935
24921
24936
24922
24937
24923
lua_getglobal(self->main_object->state,self->global_name);
24938
- lua_pushstring (self->main_object->state, name);
24939
- lua_gettable(self->main_object->state, -2);
24924
+ privateLuaCEmbd_get_field_protected (self->main_object, name);
24925
+
24940
24926
if(privateLuaCEmbedTable_ensure_type_with_key(self, name, LUA_CEMBED_NUMBER)){
24941
24927
return LUA_CEMBED_GENERIC_ERROR;
24942
24928
}
@@ -24953,8 +24939,7 @@ bool LuaCembedTable_get_bool_prop(LuaCEmbedTable *self , const char *name){
24953
24939
24954
24940
24955
24941
lua_getglobal(self->main_object->state,self->global_name);
24956
- lua_pushstring(self->main_object->state, name);
24957
- lua_gettable(self->main_object->state, -2);
24942
+ privateLuaCEmbd_get_field_protected(self->main_object,name);
24958
24943
if(privateLuaCEmbedTable_ensure_type_with_key(self, name, LUA_CEMBED_BOOL)){
24959
24944
return LUA_CEMBED_GENERIC_ERROR;
24960
24945
}
@@ -25424,16 +25409,14 @@ LuaCEmbedTable *LuaCEmbedTable_get_sub_table_by_key(LuaCEmbedTable *self, const
25424
25409
25425
25410
25426
25411
lua_getglobal(self->main_object->state,self->global_name);
25427
- lua_pushstring(self->main_object->state, name);
25428
- lua_gettable(self->main_object->state, -2);
25412
+ privateLuaCEmbd_get_field_protected(self->main_object,name);
25429
25413
if(privateLuaCEmbedTable_ensure_type_with_key(self, name, LUA_CEMBED_TABLE)){
25430
25414
PRIVATE_LUA_CEMBED_CLEAR_STACK
25431
25415
return NULL;
25432
25416
}
25433
25417
//equivalent of full_sub_table_name = table.sub_table
25434
25418
lua_getglobal(self->main_object->state,self->global_name);
25435
- lua_pushstring(self->main_object->state, name);
25436
- lua_gettable(self->main_object->state, -2);
25419
+ privateLuaCEmbd_get_field_protected(self->main_object,name);
25437
25420
char *full_sub_table_name = private_LuaCembed_format("%s_%s", self->global_name, name);
25438
25421
lua_setglobal(self->main_object->state,full_sub_table_name);
25439
25422
@@ -25479,8 +25462,8 @@ void LuaCEmbedTable_set_sub_table_prop(LuaCEmbedTable *self, const char *name, L
25479
25462
25480
25463
//equivalent of full_sub_table_name = table.sub_table
25481
25464
lua_getglobal(self->main_object->state,self->global_name);
25482
- lua_pushstring (self->main_object->state, name);
25483
- lua_gettable(self->main_object->state, -2);
25465
+ privateLuaCEmbd_get_field_protected (self->main_object, name);
25466
+
25484
25467
char *full_sub_table_name = private_LuaCembed_format("%s_%s", self->global_name, name);
25485
25468
lua_setglobal(self->main_object->state,full_sub_table_name);
25486
25469
free(full_sub_table_name);
@@ -26139,6 +26122,12 @@ int privateLuaCEmbed_main_callback_handler(lua_State *L){
26139
26122
}
26140
26123
26141
26124
if(possible_return->type == PRIVATE_LUA_CEMBED_ERROR_RESPONSE){
26125
+
26126
+ if(self->field_protection){
26127
+ private_LuaCEmbedResponse_free(possible_return);
26128
+ return PRIVATE_LUACEMBED_NO_RETURN;
26129
+ }
26130
+
26142
26131
lua_pushstring(L, possible_return->string_val);
26143
26132
privateLuaCEmbed_raise_error_not_jumping(self,possible_return->string_val);
26144
26133
private_LuaCEmbedResponse_free(possible_return);
0 commit comments