Where is the task "BRL-CAD Lua binding 1A"?
someone else already claimed and completed it
yeah, and it's been applied -- if you svn update, you'll see Select and Unselect bindings in luadatabase.cpp
can only one person complete each of those tasks?
There is a limit set for each task, more can be added if candidates show interest.
not usually, but I think in this instance, someone completed it and completed the 1b testing task which demonstrated it worked
we'd rather add more tasks that are similarly useful than have several of you do the same work, like write a different test!
Oh ok, i was just quoting lordofbikes lol.
or more bindings
if it's a more complicated task whose implementation can vary, there may be multiple copies
Is making the site for LibreCAD a complicated task?
relatively speaking, yes ... and there's lots of potential variation in the result as it's a design task -- they always have multiple instances
@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.
What is lua binding task 1a?
It was to add select and unselect all lua bindings
Do you have the link to the task? Task description would be really helpful.
@Naseef
Create Lua bindings for the following BRL-CAD C++ core interface Database methods: * Select() * UnSelectAll()
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.
"DestroyEmbeddedLuaHandleInstance(handle);"
Java-like function naming? :joy:
@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~().
thanks for info @Daniel Rossberg
BTW, not all of the "simple" functions may work this way. For example, Clone() might work in the derived classes only.
Simply, go on step by step - in small steps.
btw these are declared in protected:
void Copy(const Object& original);
bool Validate(void) const;
protected (and private) means that they are internal functions and not part of the public API.
I.e., don't provide Lua bindings for them. (It shouldn't be possible anyway.)
so I think all the bindings should be done for public
API
okay got it
Hey @Daniel Rossberg I got your message
thanks for pointing it out
btw @Daniel Rossberg do you mean I have to push the boolean value into the stack ?
yeah I got it
but if IsValid() is returning boolean values then return type should return 1;
like this
template<_GetObject getObject> static int IsValid
(
lua_State* luaState
) {
BRLCAD::Object& object = (*getObject)(luaState, 1);
lua_pushboolean(luaState, object.IsValid());
return 1;
}
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.
thanks got it
@Daniel Rossberg now I see you made two new tasks on lua
I will head towards from this https://codein.withgoogle.com/tasks/5971180779995136/?sp-organization=4884012200361984&sp-categories=1&sp-search=lua
Hey @Daniel Rossberg just created the patch. When you get time have a look binding_Halfspace.patch
Okay, will do.
I don't think that you want to change halfspace.h. And that's all what I could find in your patch.
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
?
and also the bindings should happen in halfspace.h like objectbase.h ?
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.
Hey @Daniel Rossberg if I am sure then those function that are defined in halfspace.cpp should have template right ?
I think like this Luabinding_for_halfspace.patch
see it when you are free
Hey @Daniel Rossberg is there any way to push structure type in lua ?
also any function to check it is structure type or not ?
like something related to lua_checkstring()
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.
note that this is one way that C++ is not a strict extension of C, structs have numerous caveats due to implementation differences
okay got it
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.
Where is C involved?
my fault all C++ coded
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).
sorry, that was meant as a side note. Not important for this task, but it's a detail that often surprises
thanks for info :)
I think now it should be like this
oops i commented some code part so here is the patch 5725436345057280_1577815791_halfspace_binding.patch
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 ?
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 ?
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.)
okay got it
I've just added the Halfspace to initbrlcad.cpp.
okay I will do that once I complete this
Here is the patch file lua_binding_for_Sphere.patch
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.
okay correcting the year in the copyright notice
Done !! :-)
and yeah I found some mismatch in spacings for sphere.cpp. So I will send another patch for right spacings :)
Should I name myself in AUTHORS
list @Daniel Rossberg ?
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.
okay done :)
Hey @Daniel Rossberg Since function redefination is not allowed. Any idea of naming a function ?
SetSemiMajorAxis
is overloaded so redefining is not possible but I am thinking to give separate names in lua binding.
Any name suggestion ?
Can I do like this ?
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; }
since the overloading functions are here
void SetSemiMajorAxis(const Vector3D& axis); void SetSemiMajorAxis(const Vector3D& direction, double length);
I am thinking to do perform like this
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.
hmm lua_gettop(luaState)
returns the top element of the stack
Yes, a number, which is the stack size. Try it! Test it!
Okay I implemented like this lua_binding_for_hyperboloid.patch
Hey @Daniel Rossberg I just modified the parameters numbers now here is the patch lua_binding_for_hyperboloid.patch
Diff says, that you two patches are identical. Uploaded the wrong file?
my bad
I am sorry for that
same mistake
I sent you the same file
:(
Hey @Daniel Rossberg here is the patch lua_binding_for_hyperboloid.patch
oops not this one
here is the one lua_binding_for_hyperboloid.patch
btw I have modified some spacings a little bit lua_binding_for_hyperboloid.patch
Assuring a fine patch is the recent patch
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.
okay done
:)
Hey @Daniel Rossberg Do you have any file name suggestions for testing BRLCAD.database:Title()
function ?
Since there are some file names like this
h1manshu@asus:~/brlcad/rt^3/tests/embeddedLua $ ls boundingbox.cpp CMakeLists.txt hellobrlcad.cpp helloworld.cpp selectunselect.cpp
can I name databasetitle.cpp
for testing BRLCAD.database:Title()
?
Should it look like this ?
h1manshu@asus:~/brlcad/rt^3/build $ tests-bin/databasetitle ~/brlcad/brlcad-code/build/share/db/world.g Title : Colorful version of the Moss World
@Daniel Rossberg ^^^
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.
oops just got excited
btw I saw some examples of some tests
for printing title one is the command itself and the argument passed which will be .g file
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 ...
yeah got the two function pointers
void (*stdOut)(const char* text), void (*stdErr)(const char* text)
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.
To do this, you have to catch the Lua output. This can be done by providing an own function for the Lua stdOut.
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()
?
Yes, the Lua code to be executed would be print(BRLCAD.database:Title())
.
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
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.
hmm... so Lua Title() output will be compared with C++ Title() Output
This would be an idea for a test for this function.
the late night here. I will look into it in morning
Hey @Daniel Rossberg How I can store print(BRLCAD.database.Title())
into a string ?
or how I can convert that Lua print()
into C++ string ?
I have implemented like this but I am not able to convert print()
into a string databasetitle
would .tostring() be better?
btw I want to convert without LuaState
any idea for that?
looks like there are 5 binding tasks remaining. sweet!
I am thinking to complete it
how long has each binding taken? looks like you've done about 10 of them
what was the fastest/longest?
are they getting easier now that you've done a bunch?
yeah after some binding, it's get easier
@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.
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
Should I keep the current state of work or just create new one with passing a function ? Just got confused
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?
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
?
I said "pass a ... function ... to CreateEmbeddedLuaHandleInstance()".
Where is void databasetitle(const char *text)
? I can't see it in the provided code.
So for passing a function to stdOut
I created a databasetitle
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.
oh... sorry forgot to mention it
https://paste.ofcode.org/QdTQJFgi3nnDtiDeScZCUj
This looks better.
I am just confused what that text
gonna work for void (*stdOut)(const char *text)
Now, you can write the content of the text
string to a global variable. Do you know what a global variable is?
yeah a variable which can be accessed by all
like it's scope can be seen to all
Therefore, this would be the next step.
like this const char* text = "print(BRLCAD.database:Title())";
Well, I have a bad feeling with this :wink: but if you write the code, you may see how it goes.
one doubt what that text
should contain ?
Maybe this hint helps: In your code, TheLuaScript
has to be "print(BRLCAD.database:Title())"
.
one doubt what that
text
should contain ?
What ever it contains, it's the function's parameter.
Again, write the content of text
to a global variable.
then TheLuaScript
and text
will contain same strings ?
if text
will be global varibale then it has to be like TheLuaScript
?
then
TheLuaScript
andtext
will contain same strings ?
Not in general.
if
text
will be global varibale then it has to be likeTheLuaScript
?
text
is a function parameter, not a global variable.
then I have to compare text
with C++ Title()
since text
is carrying Lua Title()
?
In principle yes, do you have the code which writes text
to a global variable?
https://paste.ofcode.org/DExtE25RS45Cvij7aZXmnZ
Well, you write TheLuaScript
to text
. However, what I recommended was writing text
to a global variable.
did you mean the content of text
will be passed to a new global varibale ?
actually I am unable to understand writing text to a global varibale
did you mean the content of
text
will be passed to a new global varibale ?
Yes.
actually I am unable to understand writing text to a global varibale
First, you need a global variable which can carry a string.
yeah got it
like this https://paste.ofcode.org/34Zp3g5gKy4fz5DirHGAxAB
Almost, the memory of text
is probably only temporary, i.e. already feed when you try to access title
. Why not std::string?
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
For handling strings there is no such data type in C. So I thought to do that in that way
There isn't much more to do than std::string title;
and title = text;
.
btw I saw that text
doesn't contain any string by using std::cout then how it is supposed to compare?
looks like title
will store the TheLuaScript
and it will be compared with C++ Title()
?
TheLuaScrip is only the program in Lua which will be executed.
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?
MemoryDatabase
. Looks like it's to be ConstDatabase
?
MemoryDatabase
. Looks like it's to beConstDatabase
?
No, its a writable BRLCAD::MemoryDatabase.
No, I meant which .g file did you used?
No, I meant which .g file did you used?
castle.g
How often was databasetitle() called?
How often was databasetitle() called?
only in 1 time EmbeddedLuaHandle* handle = CreateEmbeddedLuaHandleInstance(database, databasetitle, 0);
This doesn't mean nothing. databasetitle() will be called from within Lua. This can be multiple times.
Yeah I saw it in embeddedLua.cpp
May be there is an issue with stdOut
in embeddedlua.cpp
I will look into it in morning. Late night here
Hey @Daniel Rossberg in this function void (*stdOut)(const char* text)
what text
is referring to ?
btw I tried with several .g but still no string present in text
for databasetitle
Hey Daniel Rossberg in this function
void (*stdOut)(const char* text)
whattext
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()
.
btw I tried with several .g but still no string present in
text
fordatabasetitle
I'm currently building BRL-CAD and rt^3, and will test your stuff then.
Hey Daniel Rossberg in this function
void (*stdOut)(const char* text)
whattext
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 toprint()
.
so the text
content will be passed to Lua print()
?
No, the other way round.
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.
databasetitle()
called twice from within Lua
?
Do this:
size_t counter = 0; void databasetitle(const char* text) { ++counter; std::cout << counter << ": " << text << std::endl; }
You used helloworld.cpp as your starting point (which is okay), therefore my command line is
./helloworld havoc.g
yeah got it
the function is called two times
And, you are interested in the first call only.
yeah in first call looks like the text
is holding string but not in 2nd time
In the first call it holds a string too, namely "\ņ" (new line).
so the text
is holding Lua Title()
correct ?
I have to compare with C++ Title()
Well, it should. This would be the test.
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
and for the return values I will make it global
and those values I will use it in main()
@Daniel Rossberg so far I have done like this https://paste.ofcode.org/BWP6gC85Wrg5nbJnvmm6Gm
TheTitle
has still its memory when databasetitle()
will be called.main()
function, which has ti reflect the result of the comparison.so I will change it to std::string
Hey @Daniel Rossberg Can you apply the previous patch because so that my current patch will not mix with previous patch ?
just finished the code and I saw that previous Lua binding is not applied
Okay, done.
@Daniel Rossberg here is the patch Unit_test_for_database_title.patch
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).
okay
@Daniel Rossberg Unit_test_for_database_title.patch
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
This are all errors too, and shall result in a return value other than 0.
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
okay I understood what you said :)
You don't initialize check
and if (check == 0) {
is before the Lua script will be executed.
@Daniel Rossberg btw I am curious that is there any way I can produce the error ?
This is not so easy, but you can check with if (TheText != TheTitle)
what happens if the test fails. Or, TheTitle = database.Title() + "a"
.
yeah got all things done
since this task is part 1
then what about part 2 ?
Here is the patch unit_test_for_database_title.patch
part 2 is to make the test run automatically
automatically ?
Why is check of size_t?
automatically ?
Yes.
then I will make it int
unit_test_for_database_title.patch
automatically ?
Yes.
how ?
btw in the mean time, I completed Lua Binding for Arb8
and Paraboloid
. But I am thinking about test for part 2
You are rocking the lua interface himanshu
Hey @Sean
while I am waiting for approvation for Test but I am thinking to complete the rest Lua binding with new task for part 2
from last 5 Lua binding, I completed 2 at mean time and working in rest 3
but looks like 6 days left for end of gci
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.
okay
Hey @Daniel Rossberg can I name it to ci_database_title
or should it be database_title
?
How about "lua_database_title"? "ci" is for Core Interface.
okay
looks like it is failing btw I have done this
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)
Is there a test.g
?
nope
BTW, the test logs are in the build directory in the Testing/Temporary directory. You can look at them to find the cause.
oh... test.g
is not present
Then, you should use a database which is there.
so how coreinterface
detects test.g
?
Is that pointing to brlcad/brlcad-code/build/share/db/
?
btw @Daniel Rossberg where is test.g
present for coreinterface
?
It generates it.
yeah saw that
btw I saw that test.g can't be loaded for embededlua
looks like if (database.Load(argv[1])
is unable to load the .g
for databasetitle.cpp
@Daniel Rossberg
Maybe, you can load a database from share/db in the BRL-CAD installation directory.
Maybe, you can load a database from share/db in the BRL-CAD installation directory.
yeah I am thinking about it
btw @Daniel Rossberg is it okay if I move castle.g
to embeddedlua
and do ${CMAKE_CURRENT_SOURCE_DIR}/castle.g
because test succesfully pass for this ?
btw here is the patch add_automatic_test_for_databasetitle.patch
Oops I forgot to add castle.g in embeded Lua dir
here is the patch file after adding castle.g automatic_test_for_database_title.patch
How about ${BRLCAD_BASE_DIR}/share/db/castle.g
?
Hey @Daniel Rossberg should I complete those rest Lua binding or you will create something else ?
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.
like for an example attributes of Object interface which contains like Type()
and IsValid()
?
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:
I added some new tasks.
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 ?
Hey @Daniel Rossberg btw in meantime I completed some other Lua bindings. Should I send those patches to you ?
Yes, you can send them to me. But also uploaded t their tasks, such that they count?
looks like not so many days left
so I have to claim their respective tasks and send those patches to you
?
claim new task deadline is 21st
You mean, I shall pre-check them before you claim the tasks?
no, I mean to apply those patch without having task count
because currently I am in BRL-CAD Lua binding: Object Attributes (#1 of 2)
Well, lets start with one of them.
now ?
because currently I am in
BRL-CAD Lua binding: Object Attributes (#1 of 2)
You can abandon a task and reclaim it later.
okay
sent you one of Particle
sent you the patch. brb
just went for snacks
okay here I am
It isn't such that I don't have anything else to do :wink:
sent you the Paraboloid
Lua binding
sent you the last one Ellipsoid
rest two Lua bindings I have not started but I will work on your new task
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
?
a separate file
okay
is there any function like lua_gettop(luaState)
which not only checks number of arguments but data type of arguments passed to a function ?
suppose a function having same number of arguments but different data types
I am thinking to do in another way
(deleted)
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.
Here is the patch file for ellipsoid lua_binding_for_ellipsoid.patch
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
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.
okay I will try to search in internet
for indents are you pointing to else part ?
I think that this is a copy-n-paste thing. Every block gets only 4 additional spaces.
okay got this
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
You did a lot today :)
btw after Arb8
I will head towards the new tasks created by you
You can test with lua_istable(luaState, index)
if a parameter is a vector or not.
Hey @Daniel Rossberg I am thinking about a file name like objectatrribute.h
which is related to objectbase.h
or any you can suggest ?
@Himanshu Sekhar Nayak objectattributeiterator.~
Okay
Hey @Daniel Rossberg busy day today ?
It's called working day ;)
btw @Daniel Rossberg here is the patch for object::AtributeIterator
lua_binding_for_objectattributeiterator.patch
oops didn't given a space for heading
@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.
Geometry primitive class ?
But it can't be created by the user (only an Object can this). That's why it doesn't need an Init~() function.
Geometry primitive class ?
Arb8, Hafspace, Torus, ...
What you did in the last weeks.
oh..... got it
then after Lua binding of objectbaseiterator
,it can applied in objectbase.h
Hey @Daniel Rossberg btw I made some progress like this.
Here is it
lua_binding_for_object_atrributeiterator.patch
@Himanshu Sekhar Nayak Some remarks:
operator++
. Maybe a Next()
function. But, it wouldn't make much sense to return AttributeIterator there. Maybe, you could return Good(()
. This way, one could do things like while it.Next() do
.int PushObjectAttributeIterator ( lua_State* luaState, const BRLCAD::Object::AttributeIterator& iterator );
Noted
Himanshu Sekhar Nayak Some remarks:
- You need an equivalent to the C++
operator++
. Maybe aNext()
function. But, it wouldn't make much sense to return AttributeIterator there. Maybe, you could returnGood(()
. This way, one could do things likewhile it.Next() do
.- You need a possibility to create an AttributeIterator. Something like
int PushObjectAttributeIterator ( lua_State* luaState, const BRLCAD::Object::AttributeIterator& iterator );
- There is no need for ScriptObjectAttributeIterator. It's the same as BRLCAD::Object::AttributeIterator*.
- You need a destructor.
if we need PushObjectAttributeIterator
then we don't need CreateObjectAttributeIterator
because only Object
can create this(not by user) ?
Hey @Daniel Rossberg and also regarding destructor, are you pointing towards Destruct
function ?
btw @Daniel Rossberg can a nested class object can access parent class method ?
I don't think so
so to call Destroy
I need to declare a parent class object then I can access Destroy
This is in principle possible, if the subclass has access to its parent.
What do you think about?
Okay.
yeah then I have to use access specifier as public
so to call
Destroy
I need to declare a parent class object then I can accessDestroy
A simple delete will do it.
my overthinking :frown:
AttributeIterator is a simple data object with no "magic" memory behind. It's like a proxy for it's values (the member variables).
oh.... okay
Almost all done and just stumbled upon operator overloading
btw @Daniel Rossberg can you explain me in creating Next()
function ?
Something like
if (object->Good()) ++(*object); return object->Good();
btw @Daniel Rossberg here is the patch lua_binding_for_object_attribute.patch
You are making progress, and there isn't so much to change. Let's start with these:
BRLCAD::Object::AttributeIterator* TestObjectAttributeIterator()
by BRLCAD::Object::AttributeIterator GetObjectAttributeIterator()
. I changed brlcad/Object.h such that this became possible.... 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
.
Hi @Daniel Rossberg btw one doubt, ++object
add itself by 1 and I have to push it to the stack correct ?
++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.
then Next()
should only iterate the object
Yes, and return true if there is a ext one and false if not.
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 ?
like this
++object; if(object.Good()) return true; else return false;
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)!
Hey @Daniel Rossberg Here is the patch lua_binding_for_object_attribute.patch
@Himanshu Sekhar Nayak
*object
in GetObjectAttributeIterator()?:
has a special meaning.You mean Next
function should behave like as Good
?
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.
so Next()
should return the values that are being pushed by Good()
?
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.
@Daniel Rossberg looks like Next()
cannot return AttributeIterator
there
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
Daniel Rossberg looks like
Next()
cannot returnAttributeIterator
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.
so after increamneting the iterator I have to check if there is next value pair or not then return true or false accordingly
?
okay here is the patch and one doubt is bool can be converted to int type ? I saw this in stack overflow
lua_binding_for_object_attribute.patch
Look at the Good() function to see how to return a Boolean. You did it there!
then it should be like this
if (object.Good()) return 1; else return 0;
oh... I got it
okay @Daniel Rossberg here is the patch lua_binding_for_object_attribute.patch
You forgot one BRLCAD.Object::AttributeIterator, but despite this it looks good.
okay I will submit with corrections in dashboard
You see, Next() hasn't much code, but each line needs consideration.
yeah some times I don't know why but I overthink and ends up nothing
Maybe two things, because there is still time:
Here is the patch file @Daniel Rossberg lua_binding_for_object_attribute.patch
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.
okay
@Daniel Rossberg Submitted
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:
busy day today @Daniel Rossberg ?
As (almost) always. :)
Hey @Daniel Rossberg done some minor adding that you can add to src/embeddedLua
some_minor_addings_to_geometry_primitive_class.patch
Applied with revision 74740 :grinning_face_with_smiling_eyes:
Last updated: Jan 10 2025 at 00:48 UTC