Access via iterator Error, cannot assign to temporary value

I am trying to access the image as follows:

var frame1 = video.GetFrame (10000)
var frame2 = video.GetFrame (10000)

var frame_m = VsFrameNewGray32 (frame1.Width (), frame1.Height ())
for (var y = 0; y <frame1.Height (); ++ y) {
    for (var x = 0; y <frame1.Width (); ++ x) {
        frame_m [y] [x] = frame1 [y] [x] + frame2 [y] [x]

Types of All VsFrame Images
To do this, I added the following methods in ChaiScript:
lib-> add (:: chaiscript :: user_type (), “VsFrame”);
lib-> add (:: chaiscript :: fun (& videoscan :: frame :: ptr_t :: operator []), “[]”);
// returns videoscan :: u_line “VsFrame_ULine”
lib → add (:: chaiscript :: user_type (), “VsFrame_ULine”);
lib-> add (:: chaiscript :: fun (& videoscan :: u_line :: operator []), “[]”);
// returns videoscan :: u_pixel
lib-> add (:: chaiscript :: fun (& videoscan :: u_pixel :: operator +), “+”);
lib-> add (:: chaiscript :: fun (& videoscan :: u_pixel :: operator =), “=”);

Result of frame_m [y] [x] is an iterator that allows assignment to the corresponding pixel. But Chaiscript throws an Error exception on this construct: “Error, cannot assign to temporary value.”

This is because Chaiscript considers the result of frame_m [y] [x] as a temporary variable, which is indeed so. But functionally, it is a pointer by which an assignment can be made.

If I remove the check in struct Equation_AST_Node :: eval_internal (const chaiscript :: detail :: Dispatch_State & t_ss) in the chaiscript_eval.hpp file, but everything works fine, as I assume from the construction that I cited above.

Question: How do I get around this limitation? Just removing the IMHO exception is not the right way for a number of reasons. And I did not find how to do it right.

for a good answer you would have to provide some more info, for example what is the actual type of videoscan :: frame :: ptr_t :: operator [] and of what it returns and so on.
however, you could just use ChaiScript to bind a lambda to, say, “ptr_t :: set” and use that to assign in any way you please. not super pretty but very flexible and easy to get working.

as a sidenote - what are you doing there looks like it might end up being slow using ChaiScript. Writing an operator+ in cpp that does that nested for-loop and using that in ChaiScript would probably be a lot faster.

class frame
class ptr_t
:public boost::shared_ptr
u_line operator [](int y){

class u_line{
u_pixel operator [](unsigned x){

class u_pixel{
u_pixel operator+(const u_pixel &a) const

u_pixel& operator=(const u_pixel &arg)

How to do this is not beautiful, I guess. And I can give you several methods. But the goal is precisely a simple and beautiful record, as in my example.

The fact that the given example is slow, I understand. And it can be written in a faster style. The question is that it does not work.

hm. how about changing u_line::operator[] to return a reference to u_pixel? would’ve expected that anyway from a operator[] .

Unfortunately this is not possible. The source data is not u_pixel. Both u_pixel and u_line are wrappers over the stored data.