Page 2 of 3

Re: A Lua in game console.

Posted: Thu Feb 11, 2010 6:51 pm
by jacmoe
After some behind the scenes magic, I can now use a very newbie friendly syntax:

Code: Select all

set-campos 100 200 30
Or (maybe) better:

Code: Select all

set-camera-position 100 200 30
So with that out of the way (the 'horrible' Lisp parentheses) I can now start to craft my own language using Lisp. :)

Re: A Lua in game console.

Posted: Thu Feb 11, 2010 8:38 pm
by merlinblack
Very cool! 8)

Re: A Lua in game console.

Posted: Thu Feb 11, 2010 9:18 pm
by merlinblack
My Lua setup isn't perhaps too newbie friendly, but I guess everyone where would be easily able to figure out what this does. :)

Code: Select all

clock={}
clock.overlay = OverlayManager:createOverlay()
clock.panel = Panel( 0, 738/768, 300/1024, 30/768 )
clock.panel.element:setMaterialName( "gui/dialog.background" )
clock.overlay:add2D( clock.panel.element )
clock.text = Text( 150/1024, 5/786, "Clock" )
clock.panel:addChild( clock.text )
function clock.update()
  while clock.stop == false do
    clock.text.element:setParameter('caption', os.date() )
    wait(1)
  end
end
clock.stop = false
createTask( clock.update )
clock.overlay:show()
I'ts changing over time. Anything that annoys me, after awhile gets updated. Like the add2D function needing a overlay element rather than the Lua class that holds it....

Re: A Lua in game console.

Posted: Thu Feb 11, 2010 11:31 pm
by jacmoe
merlinblack wrote:Very cool! 8)
Your Lua solution too ! :)

I like my Lisp version - but if only I could get that damn ECL to stop crashing on me when I use quotes.. :x
I tried escaping them, but it doesn't work. Well.. :wink:

Re: A Lua in game console.

Posted: Thu Feb 11, 2010 11:50 pm
by jacmoe
Solved! :)
Got ECL 9.10.2 which works - ECL 9.12.3 doesn't.

Re: A Lua in game console.

Posted: Fri Feb 12, 2010 1:28 am
by merlinblack
To everyone using Lua, I made an Ogreish package loader function so now I can use

Code: Select all

require 'mylibrary'
to load 'mylibrary.lua' from any of the registered Ogre resource archives, including from a zip file if I want. :)

If you're interested have a look at:
http://github.com/merlinblack/Game-Engi ... resource.h
http://github.com/merlinblack/Game-Engi ... source.cpp

and parts of:
http://github.com/merlinblack/Game-Engi ... system.cpp

The functions from scriptingsystem.cpp are : int luaLibraryLoader( lua_State *L ) and void installLibraryLoader( lua_State *L )

Advanced Tutorial #1 helped a great deal here. Thanks to whoever wrote that!! :D

Re: A Lua in game console.

Posted: Mon Feb 15, 2010 6:54 pm
by jacmoe
I did a TinyScheme interpreter as well. :)
TinyScheme is the interpreter used in Script-Fu for the Gimp.
I'll put it up there - or link to it. :wink:

Re: A Lua in game console.

Posted: Mon Feb 15, 2010 11:26 pm
by merlinblack
jacmoe wrote:I did a TinyScheme interpreter as well. :)
TinyScheme is the interpreter used in Script-Fu for the Gimp.
I'll put it up there - or link to it. :wink:
Gosh! Been busy huh? :)

I was thinking the other day that TinyC would be an interesting idea. Not an interpreter but a quick compiler. I'm not sure how quick it is though, and how well it would embed.

Re: A Lua in game console.

Posted: Tue Feb 16, 2010 1:03 am
by jacmoe
Yes. I've been busy. :wink:
The problem is that both ECL and TinyScheme doesn't handle C++ member functions.
And that means that I need to test yet another candidate: mzScheme.
Apparently, it does support member functions as callbacks, so I just need to test that. :)
Will keep the topic posted..
Why?
Well, because I like multi-paradigm languages with a weight on functional programming - a nice break from imperative languages like C++.

Re: A Lua in game console.

Posted: Sun Feb 21, 2010 11:09 pm
by jacmoe
I did a mzScheme (PLT Scheme) console:
mzOgre.jpg
mzOgre.jpg (83.47 KiB) Viewed 13253 times
Now, I need to wrap the console itself in Scheme. That would be cool. :)
I already have a rather complete Ogre framework - based on the V2 Game Engine:
https://trac.v2.nl/wiki/vge
Found it when searching for mzScheme references - Scheme and Ogre: how awesome is that! :D

The wrapper is called 'The Magick Framework' and is a simple Luabind-like wrapper (using Boost).
I am now wrapping OIS and OgreBites..

Re: A Lua in game console.

Posted: Sun Feb 21, 2010 11:34 pm
by merlinblack
Again, Very Cool! 8)

Although looking at your screen shot, reminded me there is a fix for code that wraps the text. The wiki version skips a character. You may want to implement word wrap anyhow.

Also after seeing your screen shot I remembered somewhere I have a 'Haunted House' text game I wrote in GW-BASIC when I was 11, that would be fun to do in Lua :P I wonder if the floppy drive still works.....

Re: A Lua in game console.

Posted: Sun Feb 28, 2010 12:19 pm
by KakCAT
a little code snippet to accept tabs in your string @ LuaConsole::print

Code: Select all

        else if (*pos =='\t')
		{
			line.push_back (' ');							///< Push at least 1 space
			column++;

			while ((column%tabWidth)!=0)					///< fill until next tabWidth
			{
				line.push_back (' ');
				column++;
			}
		}

to be placed after the

Code: Select all

        if( *pos == '\n' || column > CONSOLE_LINE_LENGTH )
block. Requires a const int tabWidth=X; somewhere.


p.s. I don't know if the problem was in the original LuaConsole because I've modified it so much I don't know if I've introduced new bugs
p.s.2 I don't have access to the wiki, if the patch is interesting (and p.s.1 don't apply) feel free to introduce it for me :)

Re: A Lua in game console.

Posted: Mon Mar 01, 2010 12:30 am
by merlinblack
I was reading your post, and thinking, "hang on, tabs work for me...". :? Then I realised after looking at your code, that perhaps a TextOverlayElement just puts in a number of spaces where the tab character was, and my code was just getting it right accidently. :lol: I'll add this is the wiki soon for you since I'll be in there anyway. However you just use your forum login details to edit the wiki. :)

I have another fix for the LuaConsole::print as well, regarding skipping a character when wrapping to the next line. Word wrap can be left as an exercise for the reader... :P

EDIT: Wkikfied.
LuaConsole::print now looks like this

Code: Select all

void LuaConsole::print( std::string text )
{
    string line;
    string::iterator pos;
    int column;

    pos = text.begin();
    column = 1;

    while( pos != text.end() )
    {
        if( *pos == '\n' || column > CONSOLE_LINE_LENGTH )
        {
            lines.push_back( line );
            line.clear();
            if( *pos != '\n' )
              --pos;  // We want to keep this character for the next line.
  
            column = 0;
        }
        else if (*pos =='\t')
        {
           // Push at least 1 space
           line.push_back (' ');
           column++;
  
           // fill until next multiple of CONSOLE_TAB_STOP
           while ((column % CONSOLE_TAB_STOP )!=0)
           {
              line.push_back (' ');
              column++;
           }
        }
        else
        {
            line.push_back( *pos );
            column++;
        }
        
        pos++;
    }
    if( line.length() )
    {
        if( lines.size() > CONSOLE_MAX_LINES-1 )
            lines.pop_front();

        lines.push_back( line );
    }

    // Make sure last text printed is in view.
    if( lines.size() > CONSOLE_LINE_COUNT )
        start_line = lines.size() - CONSOLE_LINE_COUNT;

    textChanged = true;

    return;
}
That includes my small change and KakKat's tabbing code.

Re: A Lua in game console.

Posted: Mon Mar 01, 2010 11:19 am
by jacmoe
Well, I plan on using CEGUI for a console with proper word wrapping and multi-line commands.
Otherwise this would quickly turn into a GUI library of its own. :)

Re: A Lua in game console.

Posted: Tue Mar 23, 2010 10:21 am
by KakCAT
I suppose the answer is no, but has anyone had problems with the LuaConsole in release mode? (vs2005, sp1)
I'm getting a fault in frameStarted (in the 'text' object)

Re: A Lua in game console.

Posted: Thu Mar 25, 2010 9:19 pm
by merlinblack
KakCAT wrote:I suppose the answer is no, but has anyone had problems with the LuaConsole in release mode? (vs2005, sp1)
I'm getting a fault in frameStarted (in the 'text' object)
I'll *hopefully* give my project a test run on Windows this weekend - and specifically run a test in Release. I think it's vs2005 I have installed :roll: , been awhile since I booted Windows at home! :)

Re: A Lua in game console.

Posted: Thu Jan 26, 2012 12:23 pm
by Yati
Hey guys,

I'm having a little problem with this. The text I type does not get detected by the console. But the pressing the tidle, page-up, page-down keys works perfectly.

While stepping through the code I saw that OIS::KeyEvent::text is 0 always.

Since no one else seems to have this problem, I'm assuming I'm doing something wrong. I suspect its the way I initialize OIS.

This is my OIS initialization code:

Code: Select all

		Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***");
		OIS::ParamList pl;
		size_t windowHnd=0;
		std::ostringstream windowHndStr;

		pWindow->getCustomAttribute("WINDOW",&windowHnd);
		windowHndStr<<windowHnd;
		pl.insert(std::make_pair(std::string("WINDOW"),windowHndStr.str()));

		m_pInputManager=OIS::InputManager::createInputSystem(pl);
		
		m_pKeyboard=static_cast<OIS::Keyboard*>(m_pInputManager->createInputObject(OIS::Type::OISKeyboard,true));
		m_pKeyboard->setTextTranslation(OIS::Keyboard::TextTranslationMode::Unicode);	//I added this thinking it'll help, it didn't :(
		m_pMouse=static_cast<OIS::Mouse*>(m_pInputManager->createInputObject(OIS::Type::OISMouse,true));

		Ogre::WindowEventUtilities::addWindowEventListener(pWindow,this);
		
		m_pKeyboard->setEventCallback(this);
		m_pMouse->setEventCallback(this);
One pretty ugly solution I thought of is set OIS::KeyEvent::text to the right character based on the OIS::KC_** of the key being pressed. But that just sounds stupid even in my head.

Thanks for sharing this console code!

Re: A Lua in game console.

Posted: Fri Jan 27, 2012 4:15 am
by merlinblack
Its been awhile since I've looked at OIS (it's working in my project, so I haven't touched it) but I remember that it only fills in the 'text' member on Key Down events, and that buffered vs non-buffered may have an effect too. Sorry for the vague answer - I'm at work. :wink:

Re: A Lua in game console.

Posted: Sat Jan 28, 2012 9:04 am
by Yati
merlinblack wrote:Its been awhile since I've looked at OIS (it's working in my project, so I haven't touched it) but I remember that it only fills in the 'text' member on Key Down events, and that buffered vs non-buffered may have an effect too. Sorry for the vague answer - I'm at work. :wink:
>_< yup your spot on. I was using key up events so that answer wasn't vague at all!

I do have another question though. In the consolePrint.lua file the function myprint replaces the default print? Override it?

Re: A Lua in game console.

Posted: Sun Jan 29, 2012 1:38 am
by merlinblack
Yati wrote:I do have another question though. In the consolePrint.lua file the function myprint replaces the default print? Override it?
Short Answer: It overrides it, yes.

Long Answer: Functions are treated just the same as tables, numbers and strings etc. What it is really doing is pointing the reference named 'print' to a different function. When other code goes to call 'print', they get the new one. In that file you can see that I've made a new reference (called 'oldprint') to the old function by copying what 'print' was originally to keep the old function around should I need it. Without that, the original would get garbage collected eventually.

Re: A Lua in game console.

Posted: Wed Feb 08, 2012 11:11 pm
by shanefarris
Merlin, I like the console you created and I took a look at your test engine, and I really like the use of scripts in your engine too. For the most part when I see projects utilizing scripting abilities, most people will use Lua, or whatever as data for level loading and things like that. I think scripting data is ok if that's what you need it for, but you can do so much more with it like actually create logic with it. I like using a DB for data, and scripting for logic, and looks like you've utilized Lua very nicely.

Re: A Lua in game console.

Posted: Thu Feb 09, 2012 12:01 am
by merlinblack
shanefarris wrote:Merlin, I like the console you created and I took a look at your test engine, and I really like the use of scripts in your engine too. For the most part when I see projects utilizing scripting abilities, most people will use Lua, or whatever as data for level loading and things like that. I think scripting data is ok if that's what you need it for, but you can do so much more with it like actually create logic with it. I like using a DB for data, and scripting for logic, and looks like you've utilized Lua very nicely.
Thanks! :D

The Lua GUI code in my project has seen a revision or two, much eased by having a console there to debug, or testing out an idea off the cuff.

Re: A Lua in game console.

Posted: Wed Nov 11, 2015 12:10 pm
by randomcode

How can I use this console to control ogre like this video?


Re: A Lua in game console.

Posted: Sun Nov 15, 2015 4:13 am
by randomcode
Why does I exit the console when using task manager kill it(Because it can't be shutdown normally), I get access violation error in this code?

Code: Select all

~MyFrameListener()
    {
        mKeyboard->setEventCallback(0);
    }

Re: A Lua in game console.

Posted: Tue Jul 02, 2024 8:15 pm
by Lax

Hi all,

I know its an old topic, but maybe someone has an answer:

I'm also want to use the lua console to print out results. For example:

If I print 1 + 2, I want the result placed in the console. In this case 3

print(1 + 2)
\>> 3

Has anbody an idea how to accomplish that?

Best Regards
Lax