Giter Club home page Giter Club logo

Comments (31)

Electrux avatar Electrux commented on September 18, 2024

Yes it is desired (stdlib/term.cpp), it would be awesome if you could work on that 😁

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Only thing I don't get is adding funcs to the VM?

I see things like:

vm.funcs.add( { "colorize", 1,  1, { "str" }, FnType::MODULE, { .modfn = colorize }, true } );

But don't get what some of the parameters mean?

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Currently have this:

#ifdef linux // For getting terminal size on Linux
#include <sys/ioctl.h>
#include <unistd.h>
#endif

...

var_base_t * term_width( vm_state_t & vm, func_call_data_t & fcd )
{
	#if linux
	struct winsize size;
	ioctl( STDOUT_FILENO, TIOCGWINSZ, &size );

	return new var_int_t(size.ws_row, fcd.args[ 0 ]->parse_ctr() );
	#endif
}

...

vm.funcs.add( { "term_width", 0, 0, {}, FnType::MODULE, { .modfn = term_width }, true } );

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

see line 41 src/VM/Functions.hpp the function_t struct. Ask up if something is not understood 😁

Also, if you are going to create a new object and return it, u should set the last field (manual_res_free) of the struct to be true, and to false if you are returning an already existing object.
vm.nil is an exception here because the interpreter treats it specially. So, even if you return newly created objects, you can still return nil without having to set the last struct field to be false (since nil already exists).

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

With returning variables do I need to:

return new var_int_t(size.ws_row, fcd.args[ 0 ]->parse_ctr() );

Or can I just do:

return size.ws_row;

Looking through the other modules it would seem you need to do the earlier.

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Just built it, built fine and all tests passed. Will actually try it out now.

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Need to add Windows support after anyways.

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Seems to not work, when adding this line to the mod_term.et test, I get a segfault:

println( term_width() );

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Still get a segfault if in the term module I have this:

return new var_int_t(size.ws_row, 0 );

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

well, windows support is not built into the language right now anyway, so u can skip that part if you desire.
Also, tests do not include the feature you built so use your feature first. Only then will you know if it works or not.
Finally, for returning, you will have to do the return new thing since it is a new variable in the perspective of the language.

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

What do you mean about that thing about testing?

After changing the code of Ethereal and then the test, I run ./bootstrap.sh, then ./perform_tests.et. Surely that would work fine?

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

that would work,yes, assuming u added ur function in one of the files in tests/ directory.

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Right now I get a seg fault whenever I run the function (below):

var_base_t * term_width( vm_state_t & vm, func_call_data_t & fcd )
{
	#if linux
	struct winsize size;
	ioctl( STDOUT_FILENO, TIOCGWINSZ, &size );

	return new var_int_t( size.ws_row, fcd.args[ 0 ]->parse_ctr() );
	#endif
}

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Registration code (at the bottom of REGISTER_MODULE ( term ):

vm.funcs.add( { "term_width", 0, 0, {}, FnType::MODULE, { .modfn = term_width }, true } );

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

fcd.args is available when the function u fired gets some arguments, otherwise it is empty. So, u accessing args[0] will fail

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Should I just pass 0 or something as the 2nd var?

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

I think it was because:
#if linux would never run the code inside it, it needed to be #if __linux__

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

I got it working!

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Is now accessible via term.width

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

I'm going to add term.height now, and probably term.size which contains both as well.

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

How do you properly make a var_tuple_t? Is there any way to produce it from a proper / real tuple?

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

I've given up on size (term.size) for now. term.width (plus term_width()) and term.height (plus term_height() are fully functional.

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

for tuple,

import tuple;
tup = make_tuple( /* all tuple elements */ );
println( 'first element: ', tup.0 );

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

i will work on term.size when i reach home 😃

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

Okay, I have updated the code base so fcd.args[..]->parse_ctr() will no longer be required as an argument for creating new variables. And by the way, for your code, term width should use ws_col struct member shouldn't it?

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

Where are u performing all these additions? When you are done please do share them :)
Also, what exactly do you mean by term size? I seem to have that confused haha.

from ethereal.

CanadaHonk avatar CanadaHonk commented on September 18, 2024

Sorry, didn't see. Added in stdlib/term.cpp and include/ethereal/term.et, I also added some println of the size in tests/mod_term.et.

By size I mean probably a tuple.

I'll push ASAP.

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

Oh, alright. Also, you cannot simply push to this repository. You will have to fork it, modify there, and then create a pull request for me to merge :)

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

and, for using a tuple, you can create a vector of var_base_t * and push the row and column in it. Then create a var_tuple_t with that vector and return that.
But then you will have to access the row and column using size.0 and size.1

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

Another way would be to create a struct in include/ethereal/term.et and return that struct from a term_size() function. Then you can use size.row and size.col struct members

from ethereal.

Electrux avatar Electrux commented on September 18, 2024

I wrote the terminal size functions/structs (thanks to you). You can see the commit if you want :)
Reopen if you need to.

from ethereal.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.