static real _config_string_to_real( const char* str ) { unsigned int length = string_length( str ); unsigned int first_nonnumeric; unsigned int dot_position; if( length < 2 ) return string_to_real( str ); first_nonnumeric = string_find_first_not_of( str, "0123456789.", 0 ); if( ( first_nonnumeric == ( length - 1 ) ) && ( ( str[ first_nonnumeric ] == 'm' ) || ( str[ first_nonnumeric ] == 'M' ) ) ) { dot_position = string_find( str, '.', 0 ); if( dot_position != STRING_NPOS ) { if( string_find( str, '.', dot_position + 1 ) != STRING_NPOS ) return string_to_real( str ); //More than one dot } return string_to_real( str ) * ( REAL_C( 1024.0 ) * REAL_C( 1024.0 ) ); } if( ( first_nonnumeric == ( length - 1 ) ) && ( ( str[ first_nonnumeric ] == 'k' ) || ( str[ first_nonnumeric ] == 'K' ) ) ) { dot_position = string_find( str, '.', 0 ); if( dot_position != STRING_NPOS ) { if( string_find( str, '.', dot_position + 1 ) != STRING_NPOS ) return string_to_real( str ); //More than one dot } return string_to_real( str ) * REAL_C( 1024.0 ); } return string_to_real( str ); }
void config_parse_commandline( const char* const* cmdline, unsigned int num ) { //TODO: Implement, format --section:key=value unsigned int arg; for( arg = 0; arg < num; ++arg ) { if( string_match_pattern( cmdline[arg], "--*:*=*" ) ) { unsigned int first_sep = string_find( cmdline[arg], ':', 0 ); unsigned int second_sep = string_find( cmdline[arg], '=', 0 ); if( ( first_sep != STRING_NPOS ) && ( second_sep != STRING_NPOS ) && ( first_sep < second_sep ) ) { unsigned int section_length = first_sep - 2; unsigned int end_pos = first_sep + 1; unsigned int key_length = second_sep - end_pos; const char* section_str = cmdline[arg] + 2; const char* key_str = pointer_offset_const( cmdline[arg], end_pos ); hash_t section = hash( section_str, section_length ); hash_t key = hash( key_str, key_length ); char* value = string_substr( cmdline[arg], second_sep + 1, STRING_NPOS ); char* set_value = value; unsigned int value_length = string_length( value ); if( !value_length ) config_set_string( section, key, "" ); else if( string_equal( value, "false" ) ) config_set_bool( section, key, false ); else if( string_equal( value, "true" ) ) config_set_bool( section, key, true ); else if( ( string_find( value, '.', 0 ) != STRING_NPOS ) && ( string_find_first_not_of( value, "0123456789.", 0 ) == STRING_NPOS ) && ( string_find( value, '.', string_find( value, '.', 0 ) + 1 ) == STRING_NPOS ) ) //Exactly one "." config_set_real( section, key, string_to_real( value ) ); else if( string_find_first_not_of( value, "0123456789", 0 ) == STRING_NPOS ) config_set_int( section, key, string_to_int64( value ) ); else { if( ( value_length > 1 ) && ( value[0] == '"' ) && ( value[ value_length - 1 ] == '"' ) ) { value[ value_length - 1 ] = 0; set_value = value + 1; config_set_string( section, key, set_value ); } else { config_set_string( section, key, value ); } } log_infof( HASH_CONFIG, "Config value from command line: %.*s:%.*s = %s", section_length, section_str, key_length, key_str, set_value ); string_deallocate( value ); } } } }
void configureObject::parse_bc_info(vector<string> &orgin_text) { try { vector<string> config_block; get_configBlock("bcConfig", orgin_text, config_block); const int item_num = 5; for(auto it = config_block.begin(); it != config_block.end(); it++) { string &str = *it; bcConfig *bc = parse_bc_config(str, item_num); if(bc) { m_bc_info.add_bcConfig(bc); } } for(auto it = orgin_text.begin(); it != orgin_text.end();it++) { string &str = *it; if(string_find(str, "redisConfig")) { string redisLine; if(get_subString(str, '=', ';', redisLine) == false) throw 0; vector<string> subStringList; if(parseBraces(redisLine, subStringList)==true) { if(subStringList.size()!=3) throw 0; if((is_number(subStringList.at(1))==false)||(is_number(subStringList.at(2))==false)) throw 0; int port = atoi(subStringList.at(1).c_str()); int timeout = atoi(subStringList.at(2).c_str()); if((port>short_max)||(timeout>short_max))throw 0; m_bc_info.set_redis(subStringList.at(0), (unsigned short)port, (unsigned short)timeout); break; } } } string value; for(auto it = orgin_text.begin(); it != orgin_text.end();it++) { string &str = *it; if(string_find(str, "logLevel")) { string redisLine; if(get_subString(str, '=', ';', value) == false) throw 0; int level = atoi(value.c_str()); m_bc_info.set_logLevel(level); } } } catch(...) { g_manager_logger->emerg("bc redis config error"); exit(1); } }
static int glsl_dim_from_token(const string_const_t token) { string_const_t dim; size_t ofs = string_find(STRING_ARGS(token), '[', 0); if (ofs == STRING_NPOS) return 1; ++ofs; dim = string_substr(STRING_ARGS(token), ofs, string_find(STRING_ARGS(token), ']', ofs) - ofs); return string_to_int(STRING_ARGS(dim)); }
static NOINLINE char* _expand_string( hash_t section_current, char* str ) { char* expanded; char* variable; unsigned int var_pos, var_end_pos, variable_length, separator, var_offset; hash_t section, key; expanded = str; var_pos = string_find_string( expanded, "$(", 0 ); while( var_pos != STRING_NPOS ) { var_end_pos = string_find( expanded, ')', var_pos + 2 ); FOUNDATION_ASSERT_MSG( var_end_pos != STRING_NPOS, "Malformed config variable statement" ); variable = string_substr( expanded, var_pos, ( var_end_pos != STRING_NPOS ) ? ( 1 + var_end_pos - var_pos ) : STRING_NPOS ); section = section_current; key = 0; variable_length = string_length( variable ); separator = string_find( variable, ':', 0 ); if( separator != STRING_NPOS ) { if( separator != 2 ) section = hash( variable + 2, separator - 2 ); var_offset = separator + 1; } else { var_offset = 2; } key = hash( variable + var_offset, variable_length - ( var_offset + ( variable[ variable_length - 1 ] == ')' ? 1 : 0 ) ) ); if( expanded == str ) expanded = string_clone( str ); if( section != HASH_ENVIRONMENT ) expanded = string_replace( expanded, variable, config_string( section, key ), false ); else expanded = string_replace( expanded, variable, _expand_environment( key, variable + var_offset ), false ); string_deallocate( variable ); var_pos = string_find_string( expanded, "$(", 0 ); } #if BUILD_ENABLE_DEBUG_CONFIG if( str != expanded ) log_debugf( HASH_CONFIG, "Expanded config value \"%s\" to \"%s\"", str, expanded ); #endif return expanded; }
int string_replace_all(string *s, char *find, char *sub) { size_t i; int e; for (i = string_find(s, find, 0); i != (size_t) -1; i = string_find(s, find, i + strlen(sub))) { e = string_replace(s, i, strlen(find), sub); if (e == -1) return -1; } return 0; }
static NOINLINE const char* _expand_environment( hash_t key, char* var ) { if( key == HASH_EXECUTABLE_NAME ) return environment_executable_name(); else if( key == HASH_EXECUTABLE_DIRECTORY ) return environment_executable_directory(); else if( key == HASH_EXECUTABLE_PATH ) return environment_executable_path(); else if( key == HASH_INITIAL_WORKING_DIRECTORY ) return environment_initial_working_directory(); else if( key == HASH_CURRENT_WORKING_DIRECTORY ) return environment_current_working_directory(); else if( key == HASH_HOME_DIRECTORY ) return environment_home_directory(); else if( key == HASH_TEMPORARY_DIRECTORY ) return environment_temporary_directory(); else if( string_equal_substr( var, "variable[", 9 ) ) //variable[varname] - Environment variable named "varname" { const char* value; unsigned int end_pos = string_find( var, ']', 9 ); if( end_pos != STRING_NPOS ) var[end_pos] = 0; value = environment_variable( var ); if( end_pos != STRING_NPOS ) var[end_pos] = ']'; return value; } return ""; }
/*---------------------------------------------------------------------------- perl_substitute__() The pattern substitution function which includes loading perl interpreter and doing the pattern substitution, then returning the replaced string. arguments: input: char* string, input text char* pattern, match pattern output:char* string, output text ----------------------------------------------------------------------------*/ int perl_substitute__( void ) { SV *text; /* Perl representation for the string to be modified by substitution */ char *subst_cmd = ptoc_string(CTXTc 2); #ifdef MULTI_THREAD if( NULL == th) th = xsb_get_main_thread(); #endif /* first load the perl interpreter, if unloaded */ if (perlObjectStatus == UNLOADED) load_perl__(); text = newSV(0); sv_setpv(text, ptoc_string(CTXTc 1)); /* put the string to the SV */ if( !substitute(&text, subst_cmd) ) return(FAILURE); global_pattern_mode = is_global_pattern(subst_cmd); if (substituteString != NULL ) free(substituteString); substituteString = malloc(strlen(SvPV(text,PL_na))+1); strcpy(substituteString,SvPV(text,PL_na)); SvREFCNT_dec(text); /*release space*/ ctop_string(CTXTc 3, string_find(substituteString,1)); /*return changed text*/ return SUCCESS; }
int get_bulk_match_result__( void ) { #ifdef MULTI_THREAD if( NULL == th) th = xsb_get_main_thread(); #endif if (perlObjectStatus == UNLOADED ) { load_perl__(); return(FAILURE); } if ( bulkMatchList[ptoc_int(CTXTc 1)] == NULL ) return FAILURE; /*no match*/ else{ int match_seq_number= ptoc_int(CTXTc 1); int match_array_sz= ptoc_int(CTXTc 3); if (match_seq_number < match_array_sz) { /* c2p_string(CTXTc bulkMatchList[match_seq_number], reg_term(CTXTc 2)); */ ctop_string(CTXTc 2, (char *)string_find(bulkMatchList[match_seq_number],1)); return SUCCESS; } else return FAILURE; } }
static int _configure_do(Configure * configure, configArray * ca) { size_t i; size_t cnt = array_count(ca); String const * di; size_t j; Config * cj; String const * dj; for(i = 0; i < cnt; i++) { array_get_copy(ca, i, &configure->config); if((di = config_get(configure->config, "", "directory")) == NULL) continue; for(j = i; j < cnt; j++) { array_get_copy(ca, j, &cj); if((dj = config_get(cj, "", "directory")) == NULL) continue; if(string_find(dj, di) == NULL) break; } if(makefile(configure, di, ca, i, j) != 0) break; } return (i == cnt) ? 0 : 1; }
int String::find(char ch, int pos /* = 0 */, bool caseSensitive /* = true */) const { if (empty()) return -1; // Ignore taint in comparison functions. return string_find(m_px->dataIgnoreTaint(), m_px->size(), ch, pos, caseSensitive); }
void configureObject::parse_throttle_info(vector<string>& orgin_text) { string value; vector<string> config_block; get_configBlock("throttleConfig", orgin_text, config_block); for(auto it = config_block.begin(); it != config_block.end(); it++) { string &str = *it; throttleConfig *throttle = parse_throttle_config(str); if(throttle) { m_throttle_info.add_throttleConfig(throttle); } } for(auto it = orgin_text.begin(); it != orgin_text.end();it++) { string &str = *it; if(string_find(str, "logLevel")) { string redisLine; if(get_subString(str, '=', ';', value) == false) throw 0; int level = atoi(value.c_str()); m_throttle_info.set_logLevel(level); } } }
/* mixer_get_icon */ static String const * _mixer_get_icon(String const * id) { struct { String const * name; String const * icon; } icons[] = { { "beep", "audio-volume-high" }, { "cd", "media-cdrom" }, { "dac", "audio-card" }, { "input", "stock_mic" }, { "line", "stock_volume" }, { "master", "audio-volume-high" }, { "mic", "audio-input-microphone" }, { "monitor", "utilities-system-monitor" }, { "output", "audio-volume-high" }, { "pcm", "audio-volume-high" }, { "rec", "gtk-media-record" }, { "source", "audio-card" }, { "vol", "audio-volume-high" } }; size_t len; size_t i; for(i = 0; i < sizeof(icons) / sizeof(*icons); i++) if(strncmp(icons[i].name, id, string_length(icons[i].name)) == 0) return icons[i].icon; len = string_length(id); if(string_find(id, "sel") != NULL) return "multimedia"; else if(len > 5 && string_compare(&id[len - 5], ".mute") == 0) return "audio-volume-muted"; return "audio-volume-high"; }
int String::find(const String& s, int pos /* = 0 */, bool caseSensitive /* = true */) const { if (empty()) return -1; if (s.size() == 1) { return find(*s.data(), pos, caseSensitive); } return string_find(m_str->data(), m_str->size(), s.data(), s.size(), pos, caseSensitive); }
int String::find(const char *s, int pos /* = 0 */, bool caseSensitive /* = true */) const { assert(s); if (empty()) return -1; if (*s && *(s+1) == 0) { return find(*s, pos, caseSensitive); } return string_find(m_px->data(), m_px->size(), s, strlen(s), pos, caseSensitive); }
void input_turn(gameType * game) { /* Read and split player input into arguments for the parser */ int pos; int bufUsed = 0, bufSize = BUFFER_INCREMENT; char * buf, * arg1, * arg2, * temp, c; printf("Player (%c)> ", game->whoseTurn); /* Read stdin to buffer */ buf = (char *) malloc(sizeof(char) * bufSize); while ( (c = getchar()) != '\n' && !feof(stdin) ) { bufUsed++; /* Expand memory if needed */ if (bufSize <= bufUsed) { bufSize += BUFFER_INCREMENT; temp = (char *) malloc(sizeof(char) * bufSize); memcpy(temp, buf, sizeof(char) * bufSize-BUFFER_INCREMENT); buf = temp; free(temp); } buf[bufUsed-1] = c; } buf[bufUsed] = '\0'; /* Catch EoF-only input */ if ((bufUsed == 0) && (c != '\n')) { sysMessage(10, game); } if (buf[0]=='s') { /* Save file */ parse_turn(1, buf, "", game); } else { /* Play a turn */ pos = string_find(buf, ' '); if (pos > 0) { /* Two arguments */ arg1 = (char *) malloc( sizeof(char) * (pos+1) ); arg2 = (char *) malloc( sizeof(char) * (bufUsed-pos) ); memcpy( arg1, &buf[0], sizeof(char) * pos); memcpy( arg2, &buf[pos+1], sizeof(char) * (bufUsed-pos-1)); arg1[pos] = '\0'; arg2[strlen(buf)-pos-1] = '\0'; /* Send to parser and free memory */ parse_turn(2, arg1, arg2, game); free(arg1); free(arg2); } } free(buf); }
HOT_FUNC int String::find(CStrRef s, int pos /* = 0 */, bool caseSensitive /* = true */) const { if (empty()) return -1; if (s.size() == 1) { return find(*s.dataIgnoreTaint(), pos, caseSensitive); } // Ignore taint in comparison functions. return string_find(m_px->dataIgnoreTaint(), m_px->size(), s.dataIgnoreTaint(), s.size(), pos, caseSensitive); }
int String::find(const char *s, int pos /* = 0 */, bool caseSensitive /* = true */) const { ASSERT(s); if (empty()) return -1; if (*s && *(s+1) == 0) { return find(*s, pos, caseSensitive); } // Ignore taint in comparison functions. return string_find(m_px->dataIgnoreTaint(), m_px->size(), s, strlen(s), pos, caseSensitive); }
/* * Create a PSC record and initialize its fields. */ static Psc make_psc_rec(char *name, char arity) { Psc temp; temp = (Psc)mem_alloc(sizeof(struct psc_rec),ATOM_SPACE); // set_env(temp, 0); // set_spy(temp, 0); // set_shared(temp, 0); // set_tabled(temp, 0); set_name(temp, string_find(name, 1)); set_arity(temp, arity); init_psc_ep_info(temp); return temp; }
char* path_base_file_name( const char* path ) { unsigned int start, end; if( !path ) return string_allocate( 0 ); start = string_find_last_of( path, "/\\", STRING_NPOS ); end = string_find( path, '.', ( start != STRING_NPOS ) ? start : 0 ); //For "dot" files, i.e files with names like "/path/to/.file", return the dot name ".file" if( !end || ( end == ( start + 1 ) ) ) end = STRING_NPOS; if( start != STRING_NPOS ) return string_substr( path, start + 1, ( end != STRING_NPOS ) ? ( end - start - 1 ) : STRING_NPOS ); return string_substr( path, 0, end ); }
/* * Create a PSC record and initialize its fields. */ static Psc make_psc_rec(char *name, char arity) { Psc temp; int length; length = strlen(name); temp = (Psc)mem_alloc(sizeof(struct psc_rec)); set_env(temp, 0); set_type(temp, 0); set_spy(temp, 0); set_arity(temp, arity); set_length(temp, length); set_data(temp, 0); set_ep(temp,(byte *)&(temp->load_inst)); set_name(temp, string_find(name, 1)); cell_opcode(&(temp->load_inst)) = load_pred; temp->this_psc = temp; return temp; }
/* * Create a PSC record and initialize its fields. */ static Psc make_psc_rec(char *name, char arity) { Psc temp; temp = (Psc)mem_alloc(sizeof(struct psc_rec),ATOM_SPACE); set_type(temp, 0); temp->env = 0; // set_env(temp, 0); // set_spy(temp, 0); // set_shared(temp, 0); // set_tabled(temp, 0); temp->incr = 0; set_arity(temp, arity); set_data(temp, 0); set_ep(temp,(byte *)&(temp->load_inst)); set_name(temp, string_find(name, 1)); cell_opcode(&(temp->load_inst)) = load_pred; temp->this_psc = temp; return temp; }
xsbBool str_cat(CTXTdecl) { char *str1, *str2, *tmpstr; size_t tmpstr_len; term = ptoc_tag(CTXTc 1); term2 = ptoc_tag(CTXTc 2); if (isatom(term) && isatom(term2)) { str1 = string_val(term); str2 = string_val(term2); tmpstr_len = strlen(str1) + strlen(str2) + 1; tmpstr = (char *)mem_alloc(tmpstr_len,LEAK_SPACE); strcpy(tmpstr, str1); strcat(tmpstr, str2); str1 = string_find(tmpstr, 1); mem_dealloc(tmpstr,tmpstr_len,LEAK_SPACE); return atom_unify(CTXTc makestring(str1), ptoc_tag(CTXTc 3)); } else return FALSE; }
int get_bulk_match_result__( void ) { if (perlObjectStatus == UNLOADED ) { load_perl__(); return(FAILURE); } if ( bulkMatchList[ptoc_int(1)] == NULL ) return FAILURE; /*no match*/ else{ int match_seq_number= ptoc_int(1); int match_array_sz= ptoc_int(3); if (match_seq_number < match_array_sz) { /* c2p_string( bulkMatchList[match_seq_number], reg_term(2)); */ ctop_string(2, (char *)string_find(bulkMatchList[match_seq_number],1)); return SUCCESS; } else return FAILURE; } }
void configureObject::get_configBlock(const char* blockSym, vector<string>& orgin_text, vector<string>& result_text) { int left_braces = 0; bool config_start = false; for(auto it = orgin_text.begin(); it != orgin_text.end(); it++) { string &str = *it; if(str.empty() || str.at(0)== '#') continue;// Comments or blank lines if(config_start) { if(left_braces == 0) { if(str.find('{') != string::npos) { left_braces++; } continue; } else { int res_left_braces = 0; block_over(str, left_braces, res_left_braces); left_braces = res_left_braces; result_text.push_back(str); if(left_braces==0) { return; } } } else if(string_find(str, blockSym)) { config_start = true; if(str.find('{') != string::npos) { left_braces++; } } } }
int def(tokens_t *tp, tokens_t **ep) { tokens_t *t; preproc_t *p; strs_t *st; if (tp->ttype == TT_OPR && tp->num == OPR_SIZEOF) { tp++; syntax(tp->ttype == TT_SYM, "expected sizeof sym"); if ((p = pre(tp->str, PT_STRUCT))) { if (debug) printf("sizeof %s <- %d\n", tp->str, p->size); pullup(tp, tp+1, ep); tp--; tp->ttype = TT_NUM; tp->num = p->size; tp++; return 1; } if (debug) printf("unknown sizeof: %s (likely fwd ref)\n", tp->str); } if (tp->ttype == TT_SYM) { if ((p = pre(tp->str, PT_DEF))) { //if (debug) printf("def: preproc %s %s\n", p->str, tp->str); if (debug) printf("DEF \"%s\" <- %d\n", tp->str, p->val); tp->ttype = TT_NUM; tp->num = p->val; return 1; } if ((st = string_find(tp->str)) && (st->flags & SF_DEFINED)) { if (debug) printf("SYM is now a defined LABEL \"%s\" <- 0x%x\n", tp->str, st->val); tp->ttype = TT_NUM; tp->num = st->val; return 1; } } return 0; }
/* libvfs_get_remote_host */ static String * _libvfs_get_remote_host(char const * path) { char const file[] = "file://"; String * ret; String * p; if(path == NULL) return NULL; if(strncmp(file, path, sizeof(file) - 1) != 0) return NULL; path += sizeof(file) - 1; if((ret = string_new(path)) == NULL) return NULL; if((p = string_find(ret, "/")) == NULL) { string_delete(ret); return NULL; } *p = '\0'; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\") => \"%s\"\n", __func__, path, ret); #endif return ret; }
DllExport int call_conv expand_file() { char *file_name; char *expanded_file_name; int tlen, lose; struct passwd *pw; register char *new_dir, *p, *user_name; #ifdef MULTI_THREAD if( NULL == th) th = xsb_get_main_thread(); #endif file_name = extern_ptoc_string(1); /* If file_name is absolute, flush ...// and detect /./ and /../. If no /./ or /../ we can return right away. */ if (file_name[0] == '/') { p = file_name; lose = 0; while (*p) { if (p[0] == '/' && p[1] == '/') file_name = p + 1; if (p[0] == '/' && p[1] == '~') file_name = p + 1, lose = 1; if (p[0] == '/' && p[1] == '.' && (p[2] == '/' || p[2] == 0 || (p[2] == '.' && (p[3] == '/' || p[3] == 0)))) lose = 1; p++; } if (!lose) { ctop_string(CTXTc 2, file_name); return TRUE; } } /* Now determine directory to start with and put it in new_dir */ new_dir = 0; if (file_name[0] == '~' && file_name[1] == '/') /* prefix ~/ */ { if (!(new_dir = (char *) getenv("HOME"))) new_dir = ""; file_name++; } else /* prefix ~username/ */ { for (p = file_name; *p && (*p != '/'); p++); user_name = alloca(p - file_name + 1); bcopy (file_name, user_name, p - file_name); user_name[p - file_name] = 0; pw = (struct passwd *) getpwnam(user_name + 1); if (!pw) { fprintf(stderr, "++Error: \"%s\" is not a registered user\n", user_name + 1); ctop_string(CTXTc 2, file_name); /* return the input file name unchanged */ return TRUE; } file_name = p; new_dir = pw -> pw_dir; } /* Now concatenate the directory and name to new space in the stack frame */ tlen = (new_dir ? strlen(new_dir) + 1 : 0) + strlen(file_name) + 1; expanded_file_name = alloca(tlen); if (new_dir) strcpy(expanded_file_name, new_dir); strcat(expanded_file_name, file_name); /* Make sure you insert the newly created symbol into the symbol table. */ ctop_string(CTXTc 2, string_find(expanded_file_name, 1)); return TRUE; }
static lua_result_t lua_do_call_custom(lua_t* env, const char* method, size_t length, lua_arg_t* arg) { lua_State* state; lua_result_t result; int numargs, i; int stacksize; size_t start, next; string_const_t part; state = env->state; stacksize = lua_gettop(state); result = LUA_OK; ++env->calldepth; next = string_find(method, length, '.', 0); if (next != STRING_NPOS) { part = string_const(method, next); lua_getlglobal(state, part.str, part.length); if (lua_isnil(state, -1)) { log_errorf(HASH_LUA, ERROR_INVALID_VALUE, STRING_CONST("Invalid script call, '%.*s' is not set (%.*s)"), STRING_FORMAT(part), (int)length, method); --env->calldepth; lua_pop(state, lua_gettop(state) - stacksize); return LUA_ERROR; } else if (!lua_istable(state, -1)) { log_errorf(HASH_LUA, ERROR_INVALID_VALUE, STRING_CONST("Invalid script call, existing data '%.*s' in '%.*s' is not a table"), STRING_FORMAT(part), (int)length, method); --env->calldepth; lua_pop(state, lua_gettop(state) - stacksize); return LUA_ERROR; } //Top of stack is now table FOUNDATION_ASSERT(lua_istable(state, -1)); ++next; start = next; next = string_find(method, length, '.', next); while (next != STRING_NPOS) { part = string_const(method + start, next - start); lua_pushlstring(state, part.str, part.length); lua_gettable(state, -2); if (lua_isnil(state, -1)) { log_errorf(HASH_LUA, ERROR_INVALID_VALUE, STRING_CONST("Invalid script call, '%.*s' is not set (%.*s)"), STRING_FORMAT(part), (int)next, method); --env->calldepth; lua_pop(state, lua_gettop(state) - stacksize); return LUA_ERROR; } else if (!lua_istable(state, -1)) { log_errorf(HASH_LUA, ERROR_INVALID_VALUE, STRING_CONST("Invalid script call, existing data '%.*s' in '%.*s' is not a table"), STRING_FORMAT(part), (int)next, method); --env->calldepth; lua_pop(state, lua_gettop(state) - stacksize); return LUA_ERROR; } //Top of stack is now table FOUNDATION_ASSERT(lua_istable(state, -1)); ++next; start = next; next = string_find(method, length, '.', next); } part = string_const(method + start, length - start); lua_pushlstring(state, part.str, part.length); lua_gettable(state, -2); } else { lua_getlglobal(state, method, length); } if (lua_isnil(state, -1)) { --env->calldepth; lua_pop(state, lua_gettop(state) - stacksize); //Method does not exist in Lua context log_errorf(HASH_LUA, ERROR_INVALID_VALUE, STRING_CONST("Invalid script call, '%.*s' is not a function"), (int)length, method); return LUA_ERROR; } numargs = 0; if (arg) { numargs = (arg->num < LUA_MAX_ARGS) ? arg->num : LUA_MAX_ARGS; for (i = 0; i < numargs; ++i) { switch (arg->type[i]) { case LUADATA_PTR: lua_pushlightuserdata(state, arg->value[i].ptr); break; case LUADATA_OBJ: lua_pushobject(state, arg->value[i].obj); break; case LUADATA_INT: lua_pushinteger(state, arg->value[i].ival); break; case LUADATA_REAL: lua_pushnumber(state, arg->value[i].val); break; case LUADATA_STR: lua_pushlstring(state, arg->value[i].str, arg->size[i]); break; case LUADATA_BOOL: lua_pushboolean(state, arg->value[i].flag); break; case LUADATA_INTARR: { const int* values = arg->value[i].ptr; lua_newtable(state); for (uint16_t ia = 0; ia < arg->size[i]; ++ia) { lua_pushinteger(state, ia + 1); lua_pushinteger(state, values[ia]); lua_settable(state, -3); } break; } case LUADATA_REALARR: { const real* values = arg->value[i].ptr; lua_newtable(state); for (uint16_t ia = 0; ia < arg->size[i]; ++ia) { lua_pushinteger(state, ia + 1); lua_pushnumber(state, values[ia]); lua_settable(state, -3); } break; } default: --numargs; break; } } } //TODO: Parse return value from call if (lua_pcall(state, numargs, 0, 0) != 0) { string_const_t errmsg = {0, 0}; errmsg.str = lua_tolstring(state, -1, &errmsg.length); log_errorf(HASH_LUA, ERROR_INTERNAL_FAILURE, STRING_CONST("Calling %.*s : %.*s"), (int)length, method, STRING_FORMAT(errmsg)); result = LUA_ERROR; } --env->calldepth; lua_pop(state, lua_gettop(state) - stacksize); return result; }
int String::find(char ch, int pos /* = 0 */, bool caseSensitive /* = true */) const { if (empty()) return -1; return string_find(m_px->data(), m_px->size(), ch, pos, caseSensitive); }