public object ExecuteScript(string script, bool return_string_as_byte_array = false)
{
int script_id;
CHDK_ScriptErrorType status;
_session.CHDK_ExecuteScript(script, CHDK_ScriptLanguage.PTP_CHDK_SL_LUA, out script_id, out status);
if (status == CHDK_ScriptErrorType.PTP_CHDK_S_ERRTYPE_COMPILE)
{
object msg = GetScriptMessage(script_id, false, true);
if (msg.GetType() == typeof(string))
{
throw new Exception("script compilation error: " + (string)msg);
}
else
{
throw new Exception("script compilation error (unknown reason)");
}
}
// wait for end
while (true)
{
CHDK_ScriptStatus flags;
_session.CHDK_ScriptStatus(out flags);
if (!flags.HasFlag(CHDK_ScriptStatus.PTP_CHDK_SCRIPT_STATUS_RUN))
{
break;
}
System.Threading.Thread.Sleep(100);
}
// get result
return GetScriptMessage(script_id, return_string_as_byte_array);
}