Attempt to perform arithmetic on field 'x' (a table value) - actionscript-3

I'm working with lua-alchemy, and I'm setting a global variable in my AS3 code in this way:
_lua.setGlobal("map", _map);
With _map being a object with the following function in it:
public function get x():int
{
return 10;
}
if then I try to do something like this in Lua
local a = map.x + 1
I get the following error:
Lua script failed: luaDoString:21: attempt to perform arithmetic on field 'x' (a table value)
Does anyone knows why it does that, and how I could fix it?
EDIT :
When I print type(map.id), it prints table... Shouldn't it print number?

I found my error. According to this page, I have to use as3.tolua(map.x) to convert it to the right type.

Related

Retrieving A Function From A WebhookScript Global Variable

In WebhookScript, I can store a function in a variable with:
sub = function(a, b) {
return a - b
}
I'd like to store a function in a Global Variable so that I can use it in multiple Custom Actions. But if I've saved the above function as $sub$ then
sub2 = var('$sub$')
subX = sub(1,2)
causes an error:
Trying to invoke a non-function 'string' # line...
And
function subX(a,b){
var('$sub$')
}
when sub only contains return a - b, doesn't work either.
Obviously I need to convert the string to a function but I'm not sure whether that's possible.
I know this is a bit of an obscure language but if anyone knows how this can be done in similar languages like JavaScript and PHP, I'm happy to test out any guesses...
The solution here is to remove the function section and just enter the script, which inherits the execution scope so if my global variable $script$ is:
return 'hello ' + a
Then I can execute the function with:
a = 'world'
value = exec(var('$script$'))
echo(value)
(credit to Webhook.Site's support team for explaining this)

error related to winrt::impl::com_ref<winrt::hstring> when converting from c++/cx to c++/winrt

In cppcx, I used to have this:
auto button = safe_cast<ContentControl ^>(obj);
if (auto text = dynamic_cast<Platform::String^>(button->Content)) {
return text->Data();
}
When I try to do this to convert this code to cppwinrt:
auto button = obj.as<winrt::ContentControl>();
if (auto text = button.Content().try_as<winrt::hstring>()) {
return text.c_str();
}
I get the following error:
Error (active) E0312 no suitable user-defined conversion from "winrt::impl::com_refwinrt::hstring" to "wchar_t*" exists
I was hoping I would get a winrt::hstring as a result of the try_as and I can get the .c_str() from it, but I am getting a winrt::impl::com_refwinrt::hstring instead. What am I missing?
It looks like you want to unbox a scalar value behind an IInspectable interface (see Boxing and unboxing scalar values to IInspectable with C++/WinRT). For unboxing you'll want to use the unbox_value function template:
auto button = obj.as<winrt::ContentControl>();
if (auto text = unbox_value<winrt::hstring>(button.Content())) {
return text.c_str();
}
Although it's questionable, whether you really want to return a pointer that points into the middle of some data owned elsewhere. It's probably best to just return an hstring by value. String handling in C++/WinRT has more information on the topic.

Catch SAPSQL_DATA_LOSS

I want to catch and handle SAPSQL_DATA_LOSS in my ABAP code.
I tried this:
try.
SELECT *
FROM (rtab_name) AS rtab
WHERE (sub_condition)
into table #<sub_result>
.
catch SAPSQL_DATA_LOSS into error.
...
endtry.
But above code is not valid. I get this message:
Type "SAPSQL_DATA_LOSS" is not valid
And I tried this:
catch SYSTEM-EXCEPTIONS SAPSQL_DATA_LOSS = 123.
SELECT *
...
.
endcatch.
if sy-subrc = 123.
...
endif.
But above code gives me:
Instead of "SAPSQL_DATA_LOSS" expected "system-exception" (translated from german to english by me)
How to catch SAPSQL_DATA_LOSS?
This question is not about "why does this exception happen?". This is already solved. My code should handle the exception.
SAPSQL_DATA_LOSS is a runtime error.
As SAPSQL_DATA_LOSS is not a class-based exception, it is not possible to catch it using try catch.
As SAPSQL_DATA_LOSS is not a catchable runtime error, it is not possible to catch it using try catch SYSTEM-EXCEPTIONS.
see the below catchable runtime errors.
https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/abenueb-abfb-sysexc.htm
After some tries I can propose you a possible solution.
This is a workaround:
I don't know if it can be applied to your case, since it needs the select statement to be wrapped into an RFC function module !
The main point is that a short dump (message type X) CAN be handled in RFC calls.
So using an RFC (CALL FUNCTION 'xxxxx' destination 'NONE' for example) and using special exception SYSTEM_FAILURE, the system does not terminate the caller program, but instead it returns a SY-SUBRC > 0 with the Short dump informations in system message fields (SY-MSGxx).
STEPS
Create a Function module (RFC enabled) with your select statement input + the row type of the result table. (All parameters passed by value)
You need this last parameter since generic tables can't be passed in RFC (no "TYPE ANY TABLE" allowed)
FUNCTION Z_DYN_SEL .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(RTAB_NAME) TYPE TABNAME16
*" VALUE(SUB_CONDITION) TYPE STRING
*" VALUE(RESULT_TYPE) TYPE STRING
*"----------------------------------------------------------------------
* RTAB_NAME: DB Table
* SUB_CONDITION: WHERE Condition
* RESULT_TYPE: The ROW type of the internal table
field-symbols <sub_result> type any table.
* DEFINE LOCAL DYNAMIC TABLE TO STORE THE RESULT
data: lr_res type ref to data.
create data lr_res type standard table of (result_type).
assign lr_res->* to <sub_result>.
* DYNAMIC SELECT
select *
from (rtab_name) as rtab
where (sub_condition)
into table #<sub_result>.
* EXPORT RESULT TO A MEMORY ID, SO IT CAN BE RETRIEVED BY CALLER
export res = <sub_result> to memory id 'RES'.
Main program:
In this caller example some parameters are passed to the RFC.
KTOKD field (should be 4 chars long) is passed with a char10 value (producing your short dump).
If ANY Dump is triggered inside the function, we can now handle it.
If everything went fine, IMPORT result from the EXPORT statement inside the RFC
field-symbols <sub_result> type any table.
data: lr_res type ref to data.
create data lr_res type standard table of KNA1.
assign lr_res->* to <sub_result>.
data lv_msg type char255.
call function 'Z_DYN_SEL' destination 'NONE'
exporting
rtab_name = 'KNA1'
sub_condition = `KTOKD = 'D001xxxxxx'`
result_type = 'KNA1'
exceptions
system_failure = 1 message lv_msg.
if sy-subrc = 0.
import res = <sub_result> from memory id 'RES'.
else.
write: / lv_msg.
write : / sy-msgid, sy-msgno, sy-msgty, sy-msgv1, sy-msgv2, sy-msgv3, sy-msgv4.
endif.
RESULTS
After the RFC call in case of a short dump in the select statement, the program is not terminated and the following pieces of information are available
SY-SUBRC = 1
lv_msg is the error text (Data was lost while copying a value.)
Sy-msgid = 00
Sy-msgno = '341'
Sy-msgty = 'X'
Sy-msgv1 = 'SAPSQL_DATA_LOSS'

error: can't perform indexing operations for <unknown type> type when sourcing

With this code, saved as test.m
function test()
x = 1;
endfunction
I get the following error message when sourcing it via source(test.m) in the GUI:
>> clear
>> source (test.m)
x = 1
error: can't perform indexing operations for <unknown type> type
error: evaluating argument list element number 1
>>
Calling the function test via >> test works fine, but I'd like to know what I'm doing wrong here.
Progress:
calling just test, in the right dir seems to do it, but then what are we sourcing for?
If you run
source(test.m)
the interpreter tries to evaluate the "." subscript on the variable "test" (which is a function in your case) and then call source with the result.
What you want is to call the function source with the string "test.m" so you have to use quotes:
source ("test.m")
or don't use () in which case all arguments are passed as strings:
source test.m

How to use Transactions in cakephp

I write this code, but its not working, it gives this error
Call to a member function commit() on a non-object
Hear is my code
$datasource = $this->Arrear->getDataSource();
$datasource->begin();
if($this->Customar->saveField("total_bake",$amount) && $this->Arrear->save()){
$dataSource->commit();
return $this->redirect(array('action'=>'index'));
}else{
$dataSource->rollback();
$this->Session->setFlash('Data insert Failed','failure');
}
Variables in php(and hence in cakephp as well) are case-sensitive
http://php.net/manual/en/language.variables.basics.php
you have in your first line
$datasource = $this->Arrear->getDataSource();
but you are committing like
$dataSource->commit();
you have the data source assigned to $datasource, but not to $dataSource. The last variable even is not defined, that is why it is showing that error. So, you have to be sure you are using exactly the same variable (with same capitalization) in all places.