Stream: Google Code-in

Topic: Lua Bindings


view this post on Zulip caleb parks (Jan 04 2018 at 14:07):

Where is the task "BRL-CAD Lua binding 1A"?

view this post on Zulip Sean (Jan 04 2018 at 14:54):

someone else already claimed and completed it

view this post on Zulip Sean (Jan 04 2018 at 14:57):

yeah, and it's been applied -- if you svn update, you'll see Select and Unselect bindings in luadatabase.cpp

view this post on Zulip caleb parks (Jan 04 2018 at 15:08):

can only one person complete each of those tasks?

view this post on Zulip William Cook (Jan 04 2018 at 15:08):

There is a limit set for each task, more can be added if candidates show interest.

view this post on Zulip Sean (Jan 04 2018 at 15:09):

not usually, but I think in this instance, someone completed it and completed the 1b testing task which demonstrated it worked

view this post on Zulip Sean (Jan 04 2018 at 15:09):

we'd rather add more tasks that are similarly useful than have several of you do the same work, like write a different test!

view this post on Zulip William Cook (Jan 04 2018 at 15:09):

Oh ok, i was just quoting lordofbikes lol.

view this post on Zulip Sean (Jan 04 2018 at 15:10):

or more bindings

view this post on Zulip Sean (Jan 04 2018 at 15:10):

if it's a more complicated task whose implementation can vary, there may be multiple copies

view this post on Zulip William Cook (Jan 04 2018 at 15:11):

Is making the site for LibreCAD a complicated task?

view this post on Zulip Sean (Jan 04 2018 at 15:12):

relatively speaking, yes ... and there's lots of potential variation in the result as it's a design task -- they always have multiple instances

view this post on Zulip Daniel Rossberg (Jan 04 2018 at 20:10):

@caleb parks There were originally 3 instances of the Lua 1a task but getting the first solution I saw no room for improvements, and I wanted to commit it to our repository. The Lua tasks shall be about commonly extending the interface. However, I left the 3 instances of 1b because testing is always good.
Task 2a is substantially harder than 1a because a structure has to be returned. I want to see how you are doing before adding more of them.
However, the Lua tasks can be solved independently of each other, in contrast to the GUI tasks.

view this post on Zulip Naseef (Jan 11 2018 at 06:36):

What is lua binding task 1a?

view this post on Zulip Jeff Sieu (Jan 11 2018 at 07:28):

It was to add select and unselect all lua bindings

view this post on Zulip Naseef (Jan 11 2018 at 09:17):

Do you have the link to the task? Task description would be really helpful.

view this post on Zulip Daniel Rossberg (Jan 11 2018 at 19:30):

@Naseef

Create Lua bindings for the following BRL-CAD C++ core interface Database methods:
* Select()
* UnSelectAll()

view this post on Zulip Daniel Rossberg (Jan 11 2018 at 19:32):

There is already a test: https://sourceforge.net/p/brlcad/code/HEAD/tree/rt%5E3/trunk/tests/embeddedLua/selectunselect.cpp
You had to write another one.

view this post on Zulip Naseef (Jan 13 2018 at 08:54):

"DestroyEmbeddedLuaHandleInstance(handle);"
Java-like function naming? :joy:

view this post on Zulip Daniel Rossberg (Dec 19 2019 at 18:23):

@Himanshu Sekhar Nayak The return value of the binding functions in rt^3/src/embeddedLua is the number of values which are pushed on the stack, which is equal to the number of return values of the corresponding Lua function. I.e., if there is no return, it's 0, if it's a string, it's 1, etc..

But, this means as well that if you return something, you have to push it on the Lua stack, for example with lua_push~().

view this post on Zulip Himanshu (Dec 19 2019 at 18:35):

thanks for info @Daniel Rossberg

view this post on Zulip Daniel Rossberg (Dec 19 2019 at 18:41):

BTW, not all of the "simple" functions may work this way. For example, Clone() might work in the derived classes only.

view this post on Zulip Daniel Rossberg (Dec 19 2019 at 18:42):

Simply, go on step by step - in small steps.

view this post on Zulip Himanshu (Dec 19 2019 at 18:44):

btw these are declared in protected:

view this post on Zulip Himanshu (Dec 19 2019 at 18:45):

void Copy(const Object& original); bool Validate(void) const;

view this post on Zulip Daniel Rossberg (Dec 19 2019 at 18:46):

protected (and private) means that they are internal functions and not part of the public API.

view this post on Zulip Daniel Rossberg (Dec 19 2019 at 18:47):

I.e., don't provide Lua bindings for them. (It shouldn't be possible anyway.)

view this post on Zulip Himanshu (Dec 19 2019 at 18:47):

so I think all the bindings should be done for public API

view this post on Zulip Himanshu (Dec 19 2019 at 18:47):

okay got it

view this post on Zulip Himanshu (Dec 20 2019 at 18:35):

Hey @Daniel Rossberg I got your message

view this post on Zulip Himanshu (Dec 20 2019 at 18:35):

thanks for pointing it out

view this post on Zulip Himanshu (Dec 20 2019 at 18:46):

btw @Daniel Rossberg do you mean I have to push the boolean value into the stack ?

view this post on Zulip Himanshu (Dec 20 2019 at 18:59):

yeah I got it

view this post on Zulip Himanshu (Dec 20 2019 at 19:00):

but if IsValid() is returning boolean values then return type should return 1;

view this post on Zulip Himanshu (Dec 20 2019 at 19:00):

like this

view this post on Zulip Himanshu (Dec 20 2019 at 19:00):

template<_GetObject getObject> static int IsValid ( lua_State* luaState ) { BRLCAD::Object& object = (*getObject)(luaState, 1); lua_pushboolean(luaState, object.IsValid()); return 1; }

view this post on Zulip Daniel Rossberg (Dec 21 2019 at 14:14):

template<_GetObject getObject> static int IsValid
(
    lua_State* luaState
) {
    BRLCAD::Object& object = (*getObject)(luaState, 1);
    lua_pushboolean(luaState, object.IsValid());
    return 1;
}

Right, IsValid() pushes one value (the type is not important) on the stack, and has to return 1 therefore.

view this post on Zulip Himanshu (Dec 21 2019 at 15:15):

thanks got it

view this post on Zulip Himanshu (Dec 21 2019 at 17:36):

@Daniel Rossberg now I see you made two new tasks on lua

view this post on Zulip Himanshu (Dec 21 2019 at 17:43):

I will head towards from this https://codein.withgoogle.com/tasks/5971180779995136/?sp-organization=4884012200361984&sp-categories=1&sp-search=lua

view this post on Zulip Himanshu (Dec 23 2019 at 15:02):

Hey @Daniel Rossberg just created the patch. When you get time have a look binding_Halfspace.patch

view this post on Zulip Daniel Rossberg (Dec 23 2019 at 15:04):

Okay, will do.

view this post on Zulip Daniel Rossberg (Dec 23 2019 at 16:24):

I don't think that you want to change halfspace.h. And that's all what I could find in your patch.

view this post on Zulip Himanshu (Dec 26 2019 at 05:29):

Hey @Daniel Rossberg do you mean I have to change the functions that are implemented in halfspace.cpp into Lua code that I have implemented like in objectbase.h

view this post on Zulip Himanshu (Dec 26 2019 at 05:29):

?

view this post on Zulip Himanshu (Dec 26 2019 at 05:32):

and also the bindings should happen in halfspace.h like objectbase.h ?

view this post on Zulip Daniel Rossberg (Dec 26 2019 at 10:32):

You don't need to touch the functions you already implemented in objectbase.h.

The only file you need to change is src/embeddedLua/halfspace.cpp. Look at the functions already implemented there. Your code has to be similar to this.

view this post on Zulip Himanshu (Dec 29 2019 at 21:43):

Hey @Daniel Rossberg if I am sure then those function that are defined in halfspace.cpp should have template right ?

view this post on Zulip Himanshu (Dec 30 2019 at 08:12):

I think like this Luabinding_for_halfspace.patch

view this post on Zulip Himanshu (Dec 30 2019 at 08:12):

see it when you are free

view this post on Zulip Himanshu (Dec 30 2019 at 21:17):

Hey @Daniel Rossberg is there any way to push structure type in lua ?

view this post on Zulip Himanshu (Dec 30 2019 at 22:38):

also any function to check it is structure type or not ?

view this post on Zulip Himanshu (Dec 30 2019 at 22:38):

like something related to lua_checkstring()

view this post on Zulip Daniel Rossberg (Dec 31 2019 at 12:33):

You would need to implement Lua equivalents for the C++ structures. However, all structures needed for the Halfspace task are already there. This task is probably much easier than you might think.

BTW, did you know, that classes and structs are the same in C++? The only difference is the default access permission.

view this post on Zulip Erik (Dec 31 2019 at 14:32):

note that this is one way that C++ is not a strict extension of C, structs have numerous caveats due to implementation differences

view this post on Zulip Himanshu (Dec 31 2019 at 17:19):

okay got it

view this post on Zulip Himanshu (Dec 31 2019 at 17:26):

You would need to implement Lua equivalents for the C++ structures. However, all structures needed for the Halfspace task are already there. This task is probably much easier than you might think.

BTW, did you know, that classes and structs are the same in C++? The only difference is the default access permission.

I thought different as there is no class support in C.

view this post on Zulip Daniel Rossberg (Dec 31 2019 at 17:28):

Where is C involved?

view this post on Zulip Himanshu (Dec 31 2019 at 17:31):

my fault all C++ coded

view this post on Zulip Daniel Rossberg (Dec 31 2019 at 17:37):

The basic Lua is written in C, but the extension to embed it in BRL-CAD is written in C++ (i.e., all the code in rt^3/src/embeddedLua).

view this post on Zulip Erik (Dec 31 2019 at 17:40):

sorry, that was meant as a side note. Not important for this task, but it's a detail that often surprises

view this post on Zulip Himanshu (Dec 31 2019 at 17:42):

thanks for info :)

view this post on Zulip Himanshu (Dec 31 2019 at 17:54):

I think now it should be like this

view this post on Zulip Himanshu (Dec 31 2019 at 17:54):

halfspace_binding.patch

view this post on Zulip Himanshu (Dec 31 2019 at 18:13):

oops i commented some code part so here is the patch 5725436345057280_1577815791_halfspace_binding.patch

view this post on Zulip Himanshu (Jan 04 2020 at 12:27):

Hey @Daniel Rossberg I am just working on this task BRL-CAD Lua binding: Sphere. Does it need to be done is separate file like sphere.h and sphere.cpp or same in halfspace.cpp ?

view this post on Zulip Himanshu (Jan 04 2020 at 12:43):

I also think CreateSphere(), GetSphere(), InitSphere(), PushSphere(), TestSphere(), GetSphereMetatable() needs to be done for Sphere task but is that to be done is halfspace.cpp or in separate new file Sphere.cpp and Sphere.h ?

view this post on Zulip Daniel Rossberg (Jan 04 2020 at 13:09):

Hey Daniel Rossberg I am just working on this task BRL-CAD Lua binding: Sphere. Does it need to be done is separate file like sphere.h and sphere.cpp or same in halfspace.cpp ?

Separate files sphere.cpp and sphere.h of course :rolling_eyes:

And, initbrlcad.cpp has to be changed too. (Forgot to do this for Halfspace.)

view this post on Zulip Himanshu (Jan 04 2020 at 13:11):

okay got it

view this post on Zulip Daniel Rossberg (Jan 04 2020 at 13:16):

I've just added the Halfspace to initbrlcad.cpp.

view this post on Zulip Himanshu (Jan 04 2020 at 13:17):

okay I will do that once I complete this

view this post on Zulip Himanshu (Jan 04 2020 at 15:25):

Here is the patch file lua_binding_for_Sphere.patch

view this post on Zulip Daniel Rossberg (Jan 04 2020 at 15:37):

This looks good. The only issue I see is the year in the copyright notice. Replace 2019 by 2020 in sphere.cpp and sphere.h.

I's much of copy-n-paste, but this is what these tasks are about. If you know one, you now all ;)
I like it.

view this post on Zulip Himanshu (Jan 04 2020 at 15:40):

okay correcting the year in the copyright notice

view this post on Zulip Himanshu (Jan 04 2020 at 15:46):

Done !! :-)

view this post on Zulip Himanshu (Jan 04 2020 at 19:21):

and yeah I found some mismatch in spacings for sphere.cpp. So I will send another patch for right spacings :)

view this post on Zulip Himanshu (Jan 05 2020 at 16:18):

Should I name myself in AUTHORS list @Daniel Rossberg ?

view this post on Zulip Daniel Rossberg (Jan 05 2020 at 16:23):

This isn't mandatory, but usual. If you want to get credited, you shall add your name to the AUTHORS file. The main AUTHORS file is in the brlcad branch. If the Lua code will once move to this branch, the AUTHORS files will be merged, I think.

view this post on Zulip Himanshu (Jan 05 2020 at 16:48):

okay done :)

view this post on Zulip Himanshu (Jan 09 2020 at 17:42):

Hey @Daniel Rossberg Since function redefination is not allowed. Any idea of naming a function ?

view this post on Zulip Himanshu (Jan 09 2020 at 17:45):

SetSemiMajorAxis is overloaded so redefining is not possible but I am thinking to give separate names in lua binding.

view this post on Zulip Himanshu (Jan 09 2020 at 17:46):

Any name suggestion ?

view this post on Zulip Himanshu (Jan 09 2020 at 17:50):

Can I do like this ?

view this post on Zulip Himanshu (Jan 09 2020 at 17:52):

static int SetSemiMajorAxis
(
    lua_State* luaState
) {
    BRLCAD::Hyperboloid& object = GetHyperboloid(luaState, 1);
    BRLCAD::Vector3D     axis   = GetVector3D(luaState, 2);

    object.SetSemiMajorAxis(axis);

    return 0;
}

static int SetAnotherSemiMajorAxis
(
    lua_State* luaState
) {
    BRLCAD::Hyperboloid& object    = GetHyperboloid(luaState, 1);
    BRLCAD::Vector3D     direction = GetVector3D(luaState, 2);
    double               length    = luaL_checknumber(luaState, 3);

    object.SetSemiMajorAxis(direction, length);

    return 0;
}

view this post on Zulip Himanshu (Jan 09 2020 at 18:00):

since the overloading functions are here

        void                  SetSemiMajorAxis(const Vector3D& axis);
        void                  SetSemiMajorAxis(const Vector3D& direction,
                                               double          length);

view this post on Zulip Himanshu (Jan 09 2020 at 18:01):

I am thinking to do perform like this

view this post on Zulip Daniel Rossberg (Jan 09 2020 at 18:29):

You can overload functions in Lua, because you program deep in the guts of the interpreter. For example, you can ask for the number of parameters with lua_gettop(luaState). If there is more than one parameter, use the second function. You can find an example of this method in vector3d.cpp.

view this post on Zulip Himanshu (Jan 09 2020 at 18:36):

hmm lua_gettop(luaState) returns the top element of the stack

view this post on Zulip Daniel Rossberg (Jan 09 2020 at 18:37):

Yes, a number, which is the stack size. Try it! Test it!

view this post on Zulip Himanshu (Jan 09 2020 at 19:31):

Okay I implemented like this lua_binding_for_hyperboloid.patch

view this post on Zulip Himanshu (Jan 10 2020 at 11:56):

Hey @Daniel Rossberg I just modified the parameters numbers now here is the patch lua_binding_for_hyperboloid.patch

view this post on Zulip Daniel Rossberg (Jan 10 2020 at 18:43):

Diff says, that you two patches are identical. Uploaded the wrong file?

view this post on Zulip Himanshu (Jan 10 2020 at 19:09):

my bad

view this post on Zulip Himanshu (Jan 10 2020 at 19:10):

I am sorry for that

view this post on Zulip Himanshu (Jan 10 2020 at 19:10):

same mistake

view this post on Zulip Himanshu (Jan 10 2020 at 19:10):

I sent you the same file

view this post on Zulip Himanshu (Jan 10 2020 at 19:15):

:(

view this post on Zulip Himanshu (Jan 11 2020 at 12:49):

Hey @Daniel Rossberg here is the patch lua_binding_for_hyperboloid.patch

view this post on Zulip Himanshu (Jan 11 2020 at 12:51):

oops not this one

view this post on Zulip Himanshu (Jan 11 2020 at 12:52):

here is the one lua_binding_for_hyperboloid.patch

view this post on Zulip Himanshu (Jan 11 2020 at 12:54):

btw I have modified some spacings a little bit lua_binding_for_hyperboloid.patch

view this post on Zulip Himanshu (Jan 11 2020 at 12:55):

Assuring a fine patch is the recent patch

view this post on Zulip Daniel Rossberg (Jan 11 2020 at 12:57):

The indents look correct now.

BTW, I's simpler for me if you upload the patch to you task and set it to submitted. This way, I need to look only once at it and can approve it if it's okay.

view this post on Zulip Himanshu (Jan 11 2020 at 12:59):

okay done

view this post on Zulip Himanshu (Jan 11 2020 at 12:59):

:)

view this post on Zulip Himanshu (Jan 12 2020 at 12:25):

Hey @Daniel Rossberg Do you have any file name suggestions for testing BRLCAD.database:Title() function ?

view this post on Zulip Himanshu (Jan 12 2020 at 12:30):

Since there are some file names like this

view this post on Zulip Himanshu (Jan 12 2020 at 12:31):

h1manshu@asus:~/brlcad/rt^3/tests/embeddedLua
$ ls
boundingbox.cpp  CMakeLists.txt  hellobrlcad.cpp  helloworld.cpp  selectunselect.cpp

view this post on Zulip Himanshu (Jan 12 2020 at 12:53):

can I name databasetitle.cpp for testing BRLCAD.database:Title() ?

view this post on Zulip Himanshu (Jan 12 2020 at 15:55):

Should it look like this ?

view this post on Zulip Himanshu (Jan 12 2020 at 15:55):

h1manshu@asus:~/brlcad/rt^3/build
$ tests-bin/databasetitle ~/brlcad/brlcad-code/build/share/db/world.g
Title : Colorful version of the Moss World

view this post on Zulip Himanshu (Jan 12 2020 at 16:02):

@Daniel Rossberg ^^^

view this post on Zulip Daniel Rossberg (Jan 12 2020 at 18:59):

Don't panic, I'm not always online :sunglasses:

databasetitle is a good name for the test.

Important are the "inner values" of the test program. I.e., how it determines, if BRLCAD.database:Title() works correctly.

view this post on Zulip Himanshu (Jan 12 2020 at 19:37):

oops just got excited

view this post on Zulip Himanshu (Jan 12 2020 at 19:41):

btw I saw some examples of some tests

view this post on Zulip Himanshu (Jan 12 2020 at 19:42):

for printing title one is the command itself and the argument passed which will be .g file

view this post on Zulip Daniel Rossberg (Jan 12 2020 at 19:44):

For example, if you use hellobrlcad.cpp as a starting point for your own program: There is the line

EmbeddedLuaHandle* handle = CreateEmbeddedLuaHandleInstance(database, 0, 0);

The create function has 2 parameters which are NULL here, but can be replaced by function pointers of functions written by you (see embeddedlua.h). If you now write a function for void (*stdOut)(const char* text) which memorizes the text, and compare it with the C++ title method ...

view this post on Zulip Himanshu (Jan 12 2020 at 19:48):

yeah got the two function pointers

view this post on Zulip Himanshu (Jan 12 2020 at 19:48):

        void      (*stdOut)(const char* text),
        void      (*stdErr)(const char* text)

view this post on Zulip Daniel Rossberg (Jan 12 2020 at 20:00):

Remember, you need an automatic test for the Lua Title() function. You can do this by comparing its output with the corresponding C++ Title() method.

view this post on Zulip Daniel Rossberg (Jan 12 2020 at 20:01):

To do this, you have to catch the Lua output. This can be done by providing an own function for the Lua stdOut.

view this post on Zulip Himanshu (Jan 12 2020 at 20:05):

so basically the function that will be passed to void (*stdOut)(const char* text) will be a Lua Title() which has to be compared with C++ Title() ?

view this post on Zulip Daniel Rossberg (Jan 12 2020 at 20:14):

Yes, the Lua code to be executed would be print(BRLCAD.database:Title()).

view this post on Zulip Himanshu (Jan 12 2020 at 20:19):

if I am correct then BRLCAD.database:Title() will display

$ tests-bin/databasetitle ~/brlcad/brlcad-code/build/share/db/world.g
Title : Colorful version of the Moss World

view this post on Zulip Daniel Rossberg (Jan 12 2020 at 20:24):

No really. First, your stdOut function should catch the output. This function could display a debug message (which can be useful if the test fails), but this isn't part of the test itself. And, if you print an additional "Title :", it will disturb the test.

view this post on Zulip Himanshu (Jan 12 2020 at 20:30):

hmm... so Lua Title() output will be compared with C++ Title() Output

view this post on Zulip Daniel Rossberg (Jan 12 2020 at 20:33):

This would be an idea for a test for this function.

view this post on Zulip Himanshu (Jan 12 2020 at 20:55):

the late night here. I will look into it in morning

view this post on Zulip Himanshu (Jan 14 2020 at 14:06):

Hey @Daniel Rossberg How I can store print(BRLCAD.database.Title()) into a string ?

view this post on Zulip Himanshu (Jan 14 2020 at 14:32):

or how I can convert that Lua print() into C++ string ?

view this post on Zulip Himanshu (Jan 14 2020 at 15:00):

I have implemented like this but I am not able to convert print() into a string databasetitle

view this post on Zulip Erik (Jan 14 2020 at 15:41):

would .tostring() be better?

view this post on Zulip Himanshu (Jan 14 2020 at 17:28):

btw I want to convert without LuaState any idea for that?

view this post on Zulip Sean (Jan 14 2020 at 17:39):

looks like there are 5 binding tasks remaining. sweet!

view this post on Zulip Himanshu (Jan 14 2020 at 17:40):

I am thinking to complete it

view this post on Zulip Sean (Jan 14 2020 at 17:40):

how long has each binding taken? looks like you've done about 10 of them

view this post on Zulip Sean (Jan 14 2020 at 17:40):

what was the fastest/longest?

view this post on Zulip Sean (Jan 14 2020 at 17:40):

are they getting easier now that you've done a bunch?

view this post on Zulip Himanshu (Jan 14 2020 at 17:41):

yeah after some binding, it's get easier

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 17:46):

@Himanshu Sekhar Nayak

I have implemented like this but I am not able to convert print() into a string databasetitle

Let's start with this one, which is probable your current state of work.

I already mentioned, that you need to pass a printing function for stdout to CreateEmbeddedLuaHandleInstance(). Do this, and show me your code.

view this post on Zulip Himanshu (Jan 14 2020 at 17:46):

what was the fastest/longest?

First 4 or 5 tasks of binding took some days me to understand and apply in rest of the tasks

view this post on Zulip Himanshu (Jan 14 2020 at 17:59):

Should I keep the current state of work or just create new one with passing a function ? Just got confused

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:02):

You current state of work is obviously not the task's solution. Therefore, you have to change something and can't keep it therefore. What's your problem?

view this post on Zulip Himanshu (Jan 14 2020 at 18:04):

I am just little bit confused in passing a function to stdOut like I created void databasetitle(const char *text) so what will be the use of text ?

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:07):

I said "pass a ... function ... to CreateEmbeddedLuaHandleInstance()".
Where is void databasetitle(const char *text)? I can't see it in the provided code.

view this post on Zulip Himanshu (Jan 14 2020 at 18:12):

So for passing a function to stdOutI created a databasetitle

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:15):

Where do you pass a function to stdOut? And again, there is no void databasetitle(const char *text) in the provided code. Maybe, you want to show me code which has this function.

view this post on Zulip Himanshu (Jan 14 2020 at 18:17):

oh... sorry forgot to mention it

view this post on Zulip Himanshu (Jan 14 2020 at 18:17):

https://paste.ofcode.org/QdTQJFgi3nnDtiDeScZCUj

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:17):

This looks better.

view this post on Zulip Himanshu (Jan 14 2020 at 18:18):

I am just confused what that text gonna work for void (*stdOut)(const char *text)

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:18):

Now, you can write the content of the text string to a global variable. Do you know what a global variable is?

view this post on Zulip Himanshu (Jan 14 2020 at 18:19):

yeah a variable which can be accessed by all

view this post on Zulip Himanshu (Jan 14 2020 at 18:20):

like it's scope can be seen to all

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:20):

Therefore, this would be the next step.

view this post on Zulip Himanshu (Jan 14 2020 at 18:21):

like this const char* text = "print(BRLCAD.database:Title())";

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:23):

Well, I have a bad feeling with this :wink: but if you write the code, you may see how it goes.

view this post on Zulip Himanshu (Jan 14 2020 at 18:25):

one doubt what that text should contain ?

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:25):

Maybe this hint helps: In your code, TheLuaScript has to be "print(BRLCAD.database:Title())".

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:26):

one doubt what that text should contain ?

What ever it contains, it's the function's parameter.

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:29):

Again, write the content of text to a global variable.

view this post on Zulip Himanshu (Jan 14 2020 at 18:46):

then TheLuaScript and text will contain same strings ?

view this post on Zulip Himanshu (Jan 14 2020 at 18:47):

if text will be global varibale then it has to be like TheLuaScript ?

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:48):

then TheLuaScript and text will contain same strings ?

Not in general.

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 18:49):

if text will be global varibale then it has to be like TheLuaScript ?

textis a function parameter, not a global variable.

view this post on Zulip Himanshu (Jan 14 2020 at 19:20):

then I have to compare text with C++ Title() since text is carrying Lua Title() ?

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 19:25):

In principle yes, do you have the code which writes text to a global variable?

view this post on Zulip Himanshu (Jan 14 2020 at 19:28):

https://paste.ofcode.org/DExtE25RS45Cvij7aZXmnZ

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 19:33):

Well, you write TheLuaScript to text. However, what I recommended was writing text to a global variable.

view this post on Zulip Himanshu (Jan 14 2020 at 19:40):

did you mean the content of text will be passed to a new global varibale ?

view this post on Zulip Himanshu (Jan 14 2020 at 19:40):

actually I am unable to understand writing text to a global varibale

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 19:42):

did you mean the content of text will be passed to a new global varibale ?

Yes.

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 19:42):

actually I am unable to understand writing text to a global varibale

First, you need a global variable which can carry a string.

view this post on Zulip Himanshu (Jan 14 2020 at 19:48):

yeah got it

view this post on Zulip Himanshu (Jan 14 2020 at 19:49):

like this https://paste.ofcode.org/34Zp3g5gKy4fz5DirHGAxAB

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 19:51):

Almost, the memory of text is probably only temporary, i.e. already feed when you try to access title. Why not std::string?

view this post on Zulip Himanshu (Jan 14 2020 at 19:53):

actually I cannot relate my C into C++ and now I saw there is a new data type to handle strings which is std::string

view this post on Zulip Himanshu (Jan 14 2020 at 19:56):

For handling strings there is no such data type in C. So I thought to do that in that way

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 19:59):

There isn't much more to do than std::string title; and title = text;.

view this post on Zulip Himanshu (Jan 14 2020 at 20:04):

btw I saw that text doesn't contain any string by using std::cout then how it is supposed to compare?

view this post on Zulip Himanshu (Jan 14 2020 at 20:08):

looks like title will store the TheLuaScript and it will be compared with C++ Title() ?

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 20:10):

TheLuaScrip is only the program in Lua which will be executed.

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 20:11):

btw I saw that text doesn't contain any string by using std::cout then how it is supposed to compare?

That's remarkable. Which database have you used?

view this post on Zulip Himanshu (Jan 14 2020 at 20:12):

MemoryDatabase. Looks like it's to be ConstDatabase ?

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 20:14):

MemoryDatabase. Looks like it's to be ConstDatabase ?

No, its a writable BRLCAD::MemoryDatabase.

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 20:14):

No, I meant which .g file did you used?

view this post on Zulip Himanshu (Jan 14 2020 at 20:15):

No, I meant which .g file did you used?

castle.g

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 20:18):

How often was databasetitle() called?

view this post on Zulip Himanshu (Jan 14 2020 at 20:20):

How often was databasetitle() called?

only in 1 time EmbeddedLuaHandle* handle = CreateEmbeddedLuaHandleInstance(database, databasetitle, 0);

view this post on Zulip Daniel Rossberg (Jan 14 2020 at 20:22):

This doesn't mean nothing. databasetitle() will be called from within Lua. This can be multiple times.

view this post on Zulip Himanshu (Jan 14 2020 at 21:21):

Yeah I saw it in embeddedLua.cpp

view this post on Zulip Himanshu (Jan 14 2020 at 21:23):

May be there is an issue with stdOut in embeddedlua.cpp

view this post on Zulip Himanshu (Jan 14 2020 at 21:24):

I will look into it in morning. Late night here

view this post on Zulip Himanshu (Jan 15 2020 at 17:27):

Hey @Daniel Rossberg in this function void (*stdOut)(const char* text) what text is referring to ?

view this post on Zulip Himanshu (Jan 15 2020 at 17:28):

btw I tried with several .g but still no string present in text for databasetitle

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:31):

Hey Daniel Rossberg in this function void (*stdOut)(const char* text) what text is referring to ?

If this function pointer is not NULL, Lua will use it for sring output, for example in the Lua print() function. I.e., text is the processed string which was headed over to print().

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:32):

btw I tried with several .g but still no string present in text for databasetitle

I'm currently building BRL-CAD and rt^3, and will test your stuff then.

view this post on Zulip Himanshu (Jan 15 2020 at 17:33):

Hey Daniel Rossberg in this function void (*stdOut)(const char* text) what text is referring to ?

If this function pointer is not NULL, Lua will use it for sring output, for example in the Lua print() function. I.e., text is the processed string which was headed over to print().

so the text content will be passed to Lua print() ?

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:35):

No, the other way round.

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:38):

Just tested your version https://paste.ofcode.org/34Zp3g5gKy4fz5DirHGAxAB with

void databasetitle(const char* text)
{
    std::cout << text << std::endl;
}

It works as it should with havoc.g, and databasetitle() is called twice.

view this post on Zulip Himanshu (Jan 15 2020 at 17:45):

databasetitle() called twice from within Lua

view this post on Zulip Himanshu (Jan 15 2020 at 17:45):

?

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:46):

Do this:

size_t      counter = 0;

void databasetitle(const char* text)
{
    ++counter;

    std::cout << counter << ": " << text << std::endl;
}

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:48):

You used helloworld.cpp as your starting point (which is okay), therefore my command line is

./helloworld havoc.g

view this post on Zulip Himanshu (Jan 15 2020 at 17:48):

yeah got it

view this post on Zulip Himanshu (Jan 15 2020 at 17:48):

the function is called two times

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:49):

And, you are interested in the first call only.

view this post on Zulip Himanshu (Jan 15 2020 at 17:50):

yeah in first call looks like the text is holding string but not in 2nd time

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:51):

In the first call it holds a string too, namely "\ņ" (new line).

view this post on Zulip Himanshu (Jan 15 2020 at 17:55):

so the text is holding Lua Title() correct ?

view this post on Zulip Himanshu (Jan 15 2020 at 17:55):

I have to compare with C++ Title()

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 17:56):

Well, it should. This would be the test.

view this post on Zulip Himanshu (Jan 15 2020 at 18:02):

okay then if both Lua Title() and C++ Title() will be equal then I will print the title otherwise a error message that both the strings are not equal

view this post on Zulip Himanshu (Jan 15 2020 at 18:03):

and for the return values I will make it global

view this post on Zulip Himanshu (Jan 15 2020 at 18:03):

and those values I will use it in main()

view this post on Zulip Himanshu (Jan 15 2020 at 18:46):

@Daniel Rossberg so far I have done like this https://paste.ofcode.org/BWP6gC85Wrg5nbJnvmm6Gm

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 18:53):

view this post on Zulip Himanshu (Jan 15 2020 at 18:58):

so I will change it to std::string

view this post on Zulip Himanshu (Jan 15 2020 at 19:35):

Hey @Daniel Rossberg Can you apply the previous patch because so that my current patch will not mix with previous patch ?

view this post on Zulip Himanshu (Jan 15 2020 at 19:35):

just finished the code and I saw that previous Lua binding is not applied

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 19:45):

Okay, done.

view this post on Zulip Himanshu (Jan 15 2020 at 19:50):

@Daniel Rossberg here is the patch Unit_test_for_database_title.patch

view this post on Zulip Daniel Rossberg (Jan 15 2020 at 19:53):

Please, create a new file. You can call it databasetitle.cpp, for example. However, it#s definitely not a hello-program (although it's okay tom use one as starting point).

view this post on Zulip Himanshu (Jan 15 2020 at 19:54):

okay

view this post on Zulip Himanshu (Jan 15 2020 at 20:04):

@Daniel Rossberg Unit_test_for_database_title.patch

view this post on Zulip Himanshu (Jan 16 2020 at 18:47):

So there is no need for returning other values like -- It cannot load file, Out of memory and cannot create BRLCAD embedded Lua Handle ? @Daniel Rossberg

view this post on Zulip Daniel Rossberg (Jan 16 2020 at 18:51):

This are all errors too, and shall result in a return value other than 0.

view this post on Zulip Himanshu (Jan 16 2020 at 18:54):

btw I created a global variable which will store the 0 for success and 2 for fail. And I checked them in main() so global values will be assigned to ret

view this post on Zulip Himanshu (Jan 16 2020 at 18:57):

okay I understood what you said :)

view this post on Zulip Daniel Rossberg (Jan 16 2020 at 19:00):

You don't initialize checkand if (check == 0) { is before the Lua script will be executed.

view this post on Zulip Himanshu (Jan 16 2020 at 19:19):

@Daniel Rossberg btw I am curious that is there any way I can produce the error ?

view this post on Zulip Daniel Rossberg (Jan 16 2020 at 19:22):

This is not so easy, but you can check with if (TheText != TheTitle) what happens if the test fails. Or, TheTitle = database.Title() + "a".

view this post on Zulip Himanshu (Jan 16 2020 at 19:25):

yeah got all things done

view this post on Zulip Himanshu (Jan 16 2020 at 19:27):

since this task is part 1

view this post on Zulip Himanshu (Jan 16 2020 at 19:27):

then what about part 2 ?

view this post on Zulip Himanshu (Jan 16 2020 at 19:30):

Here is the patch unit_test_for_database_title.patch

view this post on Zulip Daniel Rossberg (Jan 16 2020 at 19:30):

part 2 is to make the test run automatically

view this post on Zulip Himanshu (Jan 16 2020 at 19:32):

automatically ?

view this post on Zulip Daniel Rossberg (Jan 16 2020 at 19:32):

Why is check of size_t?

view this post on Zulip Daniel Rossberg (Jan 16 2020 at 19:32):

automatically ?

Yes.

view this post on Zulip Himanshu (Jan 16 2020 at 19:32):

then I will make it int

view this post on Zulip Himanshu (Jan 16 2020 at 19:34):

unit_test_for_database_title.patch

view this post on Zulip Himanshu (Jan 16 2020 at 19:35):

automatically ?

Yes.

how ?

view this post on Zulip Himanshu (Jan 17 2020 at 14:20):

btw in the mean time, I completed Lua Binding for Arb8 and Paraboloid. But I am thinking about test for part 2

view this post on Zulip Sean (Jan 17 2020 at 14:21):

You are rocking the lua interface himanshu

view this post on Zulip Himanshu (Jan 17 2020 at 14:22):

Hey @Sean

view this post on Zulip Himanshu (Jan 17 2020 at 14:23):

while I am waiting for approvation for Test but I am thinking to complete the rest Lua binding with new task for part 2

view this post on Zulip Himanshu (Jan 17 2020 at 14:23):

from last 5 Lua binding, I completed 2 at mean time and working in rest 3

view this post on Zulip Himanshu (Jan 17 2020 at 14:24):

but looks like 6 days left for end of gci

view this post on Zulip Daniel Rossberg (Jan 17 2020 at 17:33):

automatically ?

Yes.

how ?

In the rt^3 build directory type make test. This will run a test called "tester_ci_primitives_01".
Look at the CMakeLists.txt file in the tests/coreInterface directory to see how to add a program to the make test target.

view this post on Zulip Himanshu (Jan 17 2020 at 19:00):

okay

view this post on Zulip Himanshu (Jan 17 2020 at 19:38):

Hey @Daniel Rossberg can I name it to ci_database_title or should it be database_title ?

view this post on Zulip Daniel Rossberg (Jan 17 2020 at 19:42):

How about "lua_database_title"? "ci" is for Core Interface.

view this post on Zulip Himanshu (Jan 17 2020 at 19:45):

okay

view this post on Zulip Himanshu (Jan 17 2020 at 19:54):

looks like it is failing btw I have done this

view this post on Zulip Himanshu (Jan 17 2020 at 19:55):

add_executable(tester_lua_database_title databasetitle.cpp)
target_link_libraries(tester_lua_database_title embeddedlua)
add_test(NAME tester_lua_database_title_01 COMMAND tester_lua_database_title test.g)

view this post on Zulip Daniel Rossberg (Jan 17 2020 at 19:55):

Is there a test.g?

view this post on Zulip Himanshu (Jan 17 2020 at 19:56):

nope

view this post on Zulip Daniel Rossberg (Jan 17 2020 at 19:57):

BTW, the test logs are in the build directory in the Testing/Temporary directory. You can look at them to find the cause.

view this post on Zulip Himanshu (Jan 17 2020 at 19:59):

oh... test.g is not present

view this post on Zulip Daniel Rossberg (Jan 17 2020 at 20:01):

Then, you should use a database which is there.

view this post on Zulip Himanshu (Jan 17 2020 at 20:10):

so how coreinterface detects test.g ?

view this post on Zulip Himanshu (Jan 17 2020 at 20:12):

Is that pointing to brlcad/brlcad-code/build/share/db/ ?

view this post on Zulip Himanshu (Jan 17 2020 at 20:18):

btw @Daniel Rossberg where is test.g present for coreinterface ?

view this post on Zulip Daniel Rossberg (Jan 17 2020 at 20:27):

It generates it.

view this post on Zulip Himanshu (Jan 17 2020 at 20:27):

yeah saw that

view this post on Zulip Himanshu (Jan 17 2020 at 20:29):

btw I saw that test.g can't be loaded for embededlua

view this post on Zulip Himanshu (Jan 17 2020 at 20:40):

looks like if (database.Load(argv[1]) is unable to load the .g for databasetitle.cpp @Daniel Rossberg

view this post on Zulip Daniel Rossberg (Jan 17 2020 at 20:59):

Maybe, you can load a database from share/db in the BRL-CAD installation directory.

view this post on Zulip Himanshu (Jan 17 2020 at 21:00):

Maybe, you can load a database from share/db in the BRL-CAD installation directory.

yeah I am thinking about it

view this post on Zulip Himanshu (Jan 17 2020 at 21:23):

btw @Daniel Rossberg is it okay if I move castle.gto embeddedlua and do ${CMAKE_CURRENT_SOURCE_DIR}/castle.g because test succesfully pass for this ?

view this post on Zulip Himanshu (Jan 17 2020 at 21:40):

btw here is the patch add_automatic_test_for_databasetitle.patch

view this post on Zulip Himanshu (Jan 17 2020 at 22:11):

Oops I forgot to add castle.g in embeded Lua dir

view this post on Zulip Himanshu (Jan 18 2020 at 08:32):

here is the patch file after adding castle.g automatic_test_for_database_title.patch

view this post on Zulip Daniel Rossberg (Jan 18 2020 at 10:26):

How about ${BRLCAD_BASE_DIR}/share/db/castle.g?

view this post on Zulip Himanshu (Jan 18 2020 at 13:35):

Hey @Daniel Rossberg should I complete those rest Lua binding or you will create something else ?

view this post on Zulip Daniel Rossberg (Jan 18 2020 at 13:42):

Well, I could create some more regarding tests, completing the Object interface (the attributes), and more flexible primitive construction (similiar to the primitive constructors in C++), if you are interested.

view this post on Zulip Himanshu (Jan 18 2020 at 13:45):

like for an example attributes of Object interface which contains like Type() and IsValid() ?

view this post on Zulip Himanshu (Jan 18 2020 at 14:26):

Well, I could create some more regarding tests, completing the Object interface (the attributes), and more flexible primitive construction (similiar to the primitive constructors in C++), if you are interested.

btw yes I am in :slight_smile:

view this post on Zulip Daniel Rossberg (Jan 18 2020 at 17:30):

I added some new tasks.

view this post on Zulip Himanshu (Jan 18 2020 at 20:07):

Hey @Daniel Rossberg In this task BRL-CAD Lua binding: Extend primitive creation features the meaning of Provide this feature for 3 primitive geometric objects, you mean like sphere, torus and many more like that ?

view this post on Zulip Himanshu (Jan 19 2020 at 12:35):

Hey @Daniel Rossberg btw in meantime I completed some other Lua bindings. Should I send those patches to you ?

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 12:39):

Yes, you can send them to me. But also uploaded t their tasks, such that they count?

view this post on Zulip Himanshu (Jan 19 2020 at 12:40):

looks like not so many days left

view this post on Zulip Himanshu (Jan 19 2020 at 12:40):

so I have to claim their respective tasks and send those patches to you

view this post on Zulip Himanshu (Jan 19 2020 at 12:40):

?

view this post on Zulip Himanshu (Jan 19 2020 at 12:41):

claim new task deadline is 21st

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 12:41):

You mean, I shall pre-check them before you claim the tasks?

view this post on Zulip Himanshu (Jan 19 2020 at 12:42):

no, I mean to apply those patch without having task count

view this post on Zulip Himanshu (Jan 19 2020 at 12:42):

because currently I am in BRL-CAD Lua binding: Object Attributes (#1 of 2)

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 12:43):

Well, lets start with one of them.

view this post on Zulip Himanshu (Jan 19 2020 at 12:43):

now ?

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 12:44):

because currently I am in BRL-CAD Lua binding: Object Attributes (#1 of 2)

You can abandon a task and reclaim it later.

view this post on Zulip Himanshu (Jan 19 2020 at 12:44):

okay

view this post on Zulip Himanshu (Jan 19 2020 at 12:58):

sent you one of Particle

view this post on Zulip Himanshu (Jan 19 2020 at 14:14):

sent you the patch. brb

view this post on Zulip Himanshu (Jan 19 2020 at 14:58):

just went for snacks

view this post on Zulip Himanshu (Jan 19 2020 at 14:58):

okay here I am

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 15:00):

It isn't such that I don't have anything else to do :wink:

view this post on Zulip Himanshu (Jan 19 2020 at 15:27):

sent you the Paraboloid Lua binding

view this post on Zulip Himanshu (Jan 19 2020 at 16:16):

sent you the last one Ellipsoid

view this post on Zulip Himanshu (Jan 19 2020 at 16:16):

rest two Lua bindings I have not started but I will work on your new task

view this post on Zulip Himanshu (Jan 19 2020 at 16:38):

Hey @Daniel Rossberg In BRL-CAD Lua binding: Object Attributes (#1 of 2) the BRLCAD::Object::AttributeIterator class has to be done in a separate file or in same objectbase.h ?

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 16:41):

a separate file

view this post on Zulip Himanshu (Jan 19 2020 at 16:43):

okay

view this post on Zulip Himanshu (Jan 19 2020 at 16:44):

is there any function like lua_gettop(luaState) which not only checks number of arguments but data type of arguments passed to a function ?

view this post on Zulip Himanshu (Jan 19 2020 at 16:45):

suppose a function having same number of arguments but different data types

view this post on Zulip Himanshu (Jan 19 2020 at 16:45):

I am thinking to do in another way

view this post on Zulip Himanshu (Jan 19 2020 at 16:45):

(deleted)

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 16:51):

is there any function like lua_gettop(luaState) which not only checks number of arguments but data type of arguments passed to a function ?

The answer is yes, but I haven't an example at hand.

view this post on Zulip Himanshu (Jan 19 2020 at 17:24):

Here is the patch file for ellipsoid lua_binding_for_ellipsoid.patch

view this post on Zulip Himanshu (Jan 19 2020 at 18:17):

btw I have implemented check_Set for Cone because both functions have same number of arguments but different type of arguments. So I have done like this https://paste.ofcode.org/acgtvLbG5JaWCaxRfu2YCw

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 18:24):

A global check_Set? This doesn't look right.
I need to look for some examples on how to distinguish between the parameter types, but can't do this at this weekend.

view this post on Zulip Himanshu (Jan 19 2020 at 18:29):

okay I will try to search in internet

view this post on Zulip Himanshu (Jan 19 2020 at 18:32):

for indents are you pointing to else part ?

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 18:33):

I think that this is a copy-n-paste thing. Every block gets only 4 additional spaces.

view this post on Zulip Himanshu (Jan 19 2020 at 18:36):

okay got this

view this post on Zulip Himanshu (Jan 19 2020 at 18:41):

A global check_Set? This doesn't look right.
I need to look for some examples on how to distinguish between the parameter types, but can't do this at this weekend.

So only Cone Lua binding task left which will depend on this

view this post on Zulip Daniel Rossberg (Jan 19 2020 at 18:42):

You did a lot today :)

view this post on Zulip Himanshu (Jan 19 2020 at 18:42):

btw after Arb8 I will head towards the new tasks created by you

view this post on Zulip Daniel Rossberg (Jan 20 2020 at 09:21):

You can test with lua_istable(luaState, index) if a parameter is a vector or not.

view this post on Zulip Himanshu (Jan 20 2020 at 14:21):

Hey @Daniel Rossberg I am thinking about a file name like objectatrribute.h which is related to objectbase.h

view this post on Zulip Himanshu (Jan 20 2020 at 14:22):

or any you can suggest ?

view this post on Zulip Daniel Rossberg (Jan 20 2020 at 18:46):

@Himanshu Sekhar Nayak objectattributeiterator.~

view this post on Zulip Himanshu (Jan 20 2020 at 18:49):

Okay

view this post on Zulip Himanshu (Jan 20 2020 at 18:57):

Hey @Daniel Rossberg busy day today ?

view this post on Zulip Daniel Rossberg (Jan 20 2020 at 19:03):

It's called working day ;)

view this post on Zulip Himanshu (Jan 20 2020 at 19:15):

btw @Daniel Rossberg here is the patch for object::AtributeIterator lua_binding_for_objectattributeiterator.patch

view this post on Zulip Himanshu (Jan 20 2020 at 19:25):

oops didn't given a space for heading

view this post on Zulip Daniel Rossberg (Jan 20 2020 at 19:46):

@Himanshu Sekhar Nayak It's not a template (base class of others), but a real well defined class/object which needs to be handled like the vector or a geometry primitive class.

view this post on Zulip Himanshu (Jan 20 2020 at 19:48):

Geometry primitive class ?

view this post on Zulip Daniel Rossberg (Jan 20 2020 at 19:49):

But it can't be created by the user (only an Object can this). That's why it doesn't need an Init~() function.

view this post on Zulip Daniel Rossberg (Jan 20 2020 at 19:49):

Geometry primitive class ?

Arb8, Hafspace, Torus, ...

view this post on Zulip Daniel Rossberg (Jan 20 2020 at 19:49):

What you did in the last weeks.

view this post on Zulip Himanshu (Jan 20 2020 at 19:50):

oh..... got it

view this post on Zulip Himanshu (Jan 20 2020 at 19:51):

then after Lua binding of objectbaseiterator,it can applied in objectbase.h

view this post on Zulip Himanshu (Jan 20 2020 at 21:37):

Hey @Daniel Rossberg btw I made some progress like this.

view this post on Zulip Himanshu (Jan 20 2020 at 21:41):

Here is it

view this post on Zulip Himanshu (Jan 20 2020 at 21:42):

lua_binding_for_object_atrributeiterator.patch

view this post on Zulip Daniel Rossberg (Jan 21 2020 at 08:38):

@Himanshu Sekhar Nayak Some remarks:

int PushObjectAttributeIterator
(
    lua_State*                               luaState,
    const BRLCAD::Object::AttributeIterator& iterator
);

view this post on Zulip Himanshu (Jan 21 2020 at 08:42):

Noted

view this post on Zulip Himanshu (Jan 21 2020 at 14:32):

Himanshu Sekhar Nayak Some remarks:

int PushObjectAttributeIterator
(
    lua_State*                               luaState,
    const BRLCAD::Object::AttributeIterator& iterator
);

if we need PushObjectAttributeIterator then we don't need CreateObjectAttributeIterator because only Object can create this(not by user) ?

view this post on Zulip Himanshu (Jan 21 2020 at 16:11):

Hey @Daniel Rossberg and also regarding destructor, are you pointing towards Destruct function ?

view this post on Zulip Himanshu (Jan 21 2020 at 17:03):

btw @Daniel Rossberg can a nested class object can access parent class method ?

view this post on Zulip Himanshu (Jan 21 2020 at 17:05):

I don't think so

view this post on Zulip Himanshu (Jan 21 2020 at 17:24):

so to call Destroy I need to declare a parent class object then I can access Destroy

view this post on Zulip Daniel Rossberg (Jan 21 2020 at 17:25):

This is in principle possible, if the subclass has access to its parent.
What do you think about?

view this post on Zulip Daniel Rossberg (Jan 21 2020 at 17:25):

Okay.

view this post on Zulip Himanshu (Jan 21 2020 at 17:26):

yeah then I have to use access specifier as public

view this post on Zulip Daniel Rossberg (Jan 21 2020 at 17:27):

so to call Destroy I need to declare a parent class object then I can access Destroy

A simple delete will do it.

view this post on Zulip Himanshu (Jan 21 2020 at 17:28):

my overthinking :frown:

view this post on Zulip Daniel Rossberg (Jan 21 2020 at 17:29):

AttributeIterator is a simple data object with no "magic" memory behind. It's like a proxy for it's values (the member variables).

view this post on Zulip Himanshu (Jan 21 2020 at 17:31):

oh.... okay

view this post on Zulip Himanshu (Jan 21 2020 at 17:37):

Almost all done and just stumbled upon operator overloading

view this post on Zulip Himanshu (Jan 21 2020 at 17:58):

btw @Daniel Rossberg can you explain me in creating Next() function ?

view this post on Zulip Daniel Rossberg (Jan 21 2020 at 18:27):

Something like

if (object->Good())
    ++(*object);

return object->Good();

view this post on Zulip Himanshu (Jan 22 2020 at 06:33):

btw @Daniel Rossberg here is the patch lua_binding_for_object_attribute.patch

view this post on Zulip Daniel Rossberg (Jan 22 2020 at 09:21):

You are making progress, and there isn't so much to change. Let's start with these:

view this post on Zulip Daniel Rossberg (Jan 22 2020 at 09:26):

... and reviewing the code again: You can remove the TestObjectAttributeIterator() function (and put their body into GetObjectAttributeIterator). The function won't be needed.
And, in PushObjectAttributeIterator() use const BRLCAD::Object::AttributeIterator& iterator.

view this post on Zulip Himanshu (Jan 22 2020 at 18:40):

Hi @Daniel Rossberg btw one doubt, ++object add itself by 1 and I have to push it to the stack correct ?

view this post on Zulip Daniel Rossberg (Jan 22 2020 at 18:46):

++object means to "increment" the iterator. What it really does, is defined in src/coreInterface/Object.cpp lines 46 - 67.
No need to push it on the stack.

view this post on Zulip Himanshu (Jan 22 2020 at 18:50):

then Next() should only iterate the object

view this post on Zulip Daniel Rossberg (Jan 22 2020 at 19:31):

Yes, and return true if there is a ext one and false if not.

view this post on Zulip Himanshu (Jan 22 2020 at 21:26):

btw, @Daniel Rossberg I am thinking to increment the object first and then call object.Good() to check and return true and false accordingly. Also to detect Next, calling Good can detect it correct ?

view this post on Zulip Himanshu (Jan 22 2020 at 21:31):

like this

view this post on Zulip Himanshu (Jan 22 2020 at 21:32):

    ++object;

    if(object.Good())
        return true;
    else
        return false;

view this post on Zulip Daniel Rossberg (Jan 22 2020 at 22:13):

Well, this true and false is exactly what Good() returns ;)

Remember what the Lua function hook returns: It's the number of return values (number of values pushed on the stack)!

view this post on Zulip Himanshu (Jan 23 2020 at 12:44):

Hey @Daniel Rossberg Here is the patch lua_binding_for_object_attribute.patch

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 14:08):

@Himanshu Sekhar Nayak

view this post on Zulip Himanshu (Jan 23 2020 at 14:20):

You mean Next function should behave like as Good ?

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 14:42):

It has to behave like a Lua function hook. For example, it has to return the number of values it puts on the stack (which are the return values of the corresponding function in the Lua script. That's why Good() returns 1, because it pushes one Boolean value on the stack.

view this post on Zulip Himanshu (Jan 23 2020 at 14:56):

so Next() should return the values that are being pushed by Good()

view this post on Zulip Himanshu (Jan 23 2020 at 14:56):

?

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 15:05):

It's the same as in every other Lua function you implemented: Push the return values on the stack (in case of Good() it's a Boolean) and return the number of these values (in case of Good() it's only one).

Therefore, what shall the Lua Next() function return? I.e., the one in a Lua script.

view this post on Zulip Himanshu (Jan 23 2020 at 15:09):

@Daniel Rossberg looks like Next() cannot return AttributeIterator there

view this post on Zulip Himanshu (Jan 23 2020 at 15:20):

It's the same as in every other Lua function you implemented: Push the return values on the stack (in case of Good() it's a Boolean) and return the number of these values (in case of Good() it's only one).

Therefore, what shall the Lua Next() function return? I.e., the one in a Lua script.

yeah return 1 if it pushes a value and return 0 if not

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 15:38):

Daniel Rossberg looks like Next() cannot return AttributeIterator there

Well, it could, but it would be better if it returns a Boolean: true, if there is a next value pair, false if not.

view this post on Zulip Himanshu (Jan 23 2020 at 15:41):

so after increamneting the iterator I have to check if there is next value pair or not then return true or false accordingly

view this post on Zulip Himanshu (Jan 23 2020 at 15:41):

?

view this post on Zulip Himanshu (Jan 23 2020 at 16:23):

okay here is the patch and one doubt is bool can be converted to int type ? I saw this in stack overflow

view this post on Zulip Himanshu (Jan 23 2020 at 16:23):

lua_binding_for_object_attribute.patch

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 16:31):

Look at the Good() function to see how to return a Boolean. You did it there!

view this post on Zulip Himanshu (Jan 23 2020 at 16:59):

then it should be like this

view this post on Zulip Himanshu (Jan 23 2020 at 16:59):

    if (object.Good())
        return 1;
    else
        return 0;

view this post on Zulip Himanshu (Jan 23 2020 at 17:01):

oh... I got it

view this post on Zulip Himanshu (Jan 23 2020 at 17:06):

okay @Daniel Rossberg here is the patch lua_binding_for_object_attribute.patch

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 17:08):

You forgot one BRLCAD.Object::AttributeIterator, but despite this it looks good.

view this post on Zulip Himanshu (Jan 23 2020 at 17:09):

okay I will submit with corrections in dashboard

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 17:10):

You see, Next() hasn't much code, but each line needs consideration.

view this post on Zulip Himanshu (Jan 23 2020 at 17:10):

yeah some times I don't know why but I overthink and ends up nothing

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 17:24):

Maybe two things, because there is still time:

view this post on Zulip Himanshu (Jan 23 2020 at 17:29):

Here is the patch file @Daniel Rossberg lua_binding_for_object_attribute.patch

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 17:31):

You forgot the first line in objectattributeiterator.h, which is a new file too.
And then, you can upload it to the task in your dashboard.

view this post on Zulip Himanshu (Jan 23 2020 at 17:35):

okay

view this post on Zulip Himanshu (Jan 23 2020 at 17:40):

@Daniel Rossberg Submitted

view this post on Zulip Himanshu (Jan 23 2020 at 17:51):

Very much Thanks @Daniel Rossberg I got to learn and implement more and more things from you. This 1 1/2 months, I got to learn many things from you and from this Organisation. I hope to learn more and more from this Organisation and I will push myself for being better day to day :slight_smile:

view this post on Zulip Himanshu (Jan 23 2020 at 18:00):

busy day today @Daniel Rossberg ?

view this post on Zulip Daniel Rossberg (Jan 23 2020 at 18:15):

As (almost) always. :)

view this post on Zulip Himanshu (Jan 24 2020 at 13:46):

Hey @Daniel Rossberg done some minor adding that you can add to src/embeddedLuasome_minor_addings_to_geometry_primitive_class.patch

view this post on Zulip Daniel Rossberg (Jan 24 2020 at 18:00):

Applied with revision 74740 :grinning_face_with_smiling_eyes:


Last updated: Oct 09 2024 at 00:44 UTC