Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems to create the winMessage() function.. #1

Open
tuxd3v opened this issue Dec 19, 2019 · 1 comment
Open

problems to create the winMessage() function.. #1

tuxd3v opened this issue Dec 19, 2019 · 1 comment

Comments

@tuxd3v
Copy link

tuxd3v commented Dec 19, 2019

hello,
I like the Idea of having a lua newt binding library :)
I am trying to add function WinMessage()

static int L_WinMessage( lua_State *L ) {
	const char * title;
	const char * buttonText;
	const char * text;
	/*int result;*/
	unsigned int width;
	unsigned int height	= 1;
	unsigned int cols	= 20;
	unsigned int result;

	/* Check if they are Strings if yes, return them..*/
	title		= luaL_checkstring( L, 1 );
	buttonText	= luaL_checkstring( L, 2 );
	text		= luaL_checkstring( L, 3 );
	lua_pop( L, 3 );

	width		= strlen( title );
	if( strlen( buttonText ) > width )
		width = strlen( buttonText );
	if( strlen( text ) > width )
		width = strlen( text );

	height = ( width%cols != 0 ) ? ( ( width / cols ) + 1 ) : ( width / cols );

	result = newtCenteredWindow( width, height, title );
	if( ! result  ){
		/* add form, with a label inside and a button at the end..*/

		lua_pushnil( L );
		return 1;
	}else{
		lua_pushboolean( L, result );
	}
	return 1;
}

The problem I know almost nothing about newt Library :(
I am stuck there..

It seems by the 3 examples that maybe I will need a form to put a label inside, and a button at the end..?
I can't write a string to root of Window directly or something close?

Thanks in Advance,
Best Regards,
tux

@tuxd3v
Copy link
Author

tuxd3v commented Dec 19, 2019

well, seems that I miss-understand a lot of newt..
The L_WinMessage:

static int L_WinMessage( lua_State *L ) {
	char * title		= NULL;
	char * buttonText	= NULL;
	char * text		= NULL;
	/* Check if they are Strings if yes, return them..*/
	title		= ( char* )luaL_checkstring( L, 1 );
	buttonText	= ( char* )luaL_checkstring( L, 2 );
	text		= ( char* )luaL_checkstring( L, 3 );
	lua_pop( L, 3 );

	newtWinMessage( title, buttonText, text );
	lua_pushnil( L );

	return 1;
}

And it works, I don't know about the string allocation memory and de-allocation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant