User forums > Using Code::Blocks
[RESOLVED]Squirrel set $(var_name)
Suryavarman:
Hi,
Before every builds and for every projects, I have create this script to set my envars without to use that: VAR1 = [[parse cfg, get keyvalue return value]]
--- Code: ---local deps_config_filename = _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
assert(config_exist);
if(config_exist)
{
local file_content = IO.ReadFileContents(deps_config_filename);
local groups = GetArrayFromString(file_content, _T("["), true);
for(local i = 0; i < groups.GetCount(); i++)
{
local group = GetArrayFromString(groups.Item(i), _T("]"), true);
local groupName = group.Item(0);
local values = GetArrayFromString(group.Item(1), _T("\n"), true);
print("groupName " + i + ": " + groupName);
for(local j = 0; j < values.GetCount(); j++)
{
local keyvalue = GetArrayFromString(values.Item(j), _T("="), true);
if(keyvalue.GetCount() != 2)
{
ShowError(_T("Pour le groupe: " + groupName + " et valeur: " + j + " il y a plus d'un charactère '='."));
}
for(local k = 0; k < keyvalue.GetCount(); k++)
{
local key = keyvalue.Item(0).MakeUpper();
local value = keyvalue.Item(1);
key = ::EscapeSpaces(key);
value = ::EscapeSpaces(value);
// $(key) = value;
print("key: " + key + " value: " + value));
}
}
}
}
--- End code ---
But I don't know how to set the value.
$(key) = value;
Can you help me ?
oBFusCATed:
Have you tried printing the value instead of returning it from the [[ ... ]] construct?
Suryavarman:
:o
If i copy past the script into:
Project build options > Pre/post build steps:
I have this error:
Running project pre-build steps
--- Code: ---local deps_config_filename = _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
/bin/sh: 1: Syntax error: "(" unexpected
Process terminated with status 2 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
--- End code ---
If attach the script from the Project/target > Build Scripts
I have this error:
--- Code: ---AN ERROR HAS OCCURED [assertion failed]
CALLSTACK
*FUNCTION [main()] /home/gandi/Working/Ma/code/API//src/LoadConfig.script line [4]
LOCALS
[config_exist] false
[deps_config_filename] INSTANCE
[this] TABLE
--- End code ---
The relative path doesn't work (but it's work from the scriping console)
I have to fix it and will say you if it's work or not.
Thank you for you answer.
Suryavarman:
With this attached script it doesn't work (Project/target > Build Scripts):
--- Code: ---// http://wiki.codeblocks.org/index.php/Build_scripts
function SetBuildOptions(base)
{
local deps_config_filename = ::ReplaceMacros(_T("$(PROJECT_DIR)"));
deps_config_filename += _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
assert(config_exist);
if(config_exist)
{
local file_content = IO.ReadFileContents(deps_config_filename);
local groups = GetArrayFromString(file_content, _T("["), true);
for(local i = 0; i < groups.GetCount(); i++)
{
local group = GetArrayFromString(groups.Item(i), _T("]"), true);
local groupName = group.Item(0);
local values = GetArrayFromString(group.Item(1), _T("\n"), true);
//print("groupName " + i + ": " + groupName);
for(local j = 0; j < values.GetCount(); j++)
{
local keyvalue = GetArrayFromString(values.Item(j), _T("="), true);
if(keyvalue.GetCount() != 2)
{
ShowError(_T("Pour le groupe: " + groupName + " et valeur: " + j + " il y a plus d'un charactère '='."));
}
local key = keyvalue.Item(0).MakeUpper();
local value = keyvalue.Item(1);
key = ::EscapeSpaces(key);
value = ::EscapeSpaces(value);
// $(key) = value;
print(key + "=" + value +"\n");
}
}
}
}
--- End code ---
Suryavarman:
I have try to use SetCommandsBeforeBuild. But nothing happen. The echo command send to the CommandsBeforeBuild doesn't appear/works.
--- Code: ---
function SetBuildOptions(base)
{
local deps_config_filename = ::ReplaceMacros(_T("$(PROJECT_DIR)"));
deps_config_filename += _T("../../dependencies/dependencies.cfg");
local config_exist = IO.FileExists(deps_config_filename);
assert(config_exist);
if(config_exist)
{
local file_content = IO.ReadFileContents(deps_config_filename);
local groups = GetArrayFromString(file_content, _T("["), true);
local commands = wxArrayString();
for(local i = 0; i < groups.GetCount(); i++)
{
local group = GetArrayFromString(groups.Item(i), _T("]"), true);
local groupName = group.Item(0);
local values = GetArrayFromString(group.Item(1), _T("\n"), true);
//print("groupName " + i + ": " + groupName);
for(local j = 0; j < values.GetCount(); j++)
{
local keyvalue = GetArrayFromString(values.Item(j), _T("="), true);
if(keyvalue.GetCount() != 2)
{
ShowError(_T("Pour le groupe: " + groupName + " et valeur: " + j + " il y a plus d'un charactère '='."));
}
local key = keyvalue.Item(0).MakeUpper();
local value = keyvalue.Item(1);
key = ::EscapeSpaces(key);
value = ::EscapeSpaces(value);
// $(key) = value;
commands.Add(key + _T("=\"") + value + _T("\""), 1);
commands.Add(_T("echo $(") + key + _T(")"), 1);
//print(key + "=" + value +"\n");
}
}
for(local i = 0; i < commands.GetCount(); i++)
{
print(commands.Item(i));
}
base.SetCommandsBeforeBuild(commands);
}
}
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version