Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Python console  (Read 3353 times)

0 Members and 1 Guest are viewing this topic.

lezebulon

  • Full Member
  • ***
  • Posts: 235
    • View Profile
SFML Python console
« on: December 26, 2015, 06:42:19 pm »


Hi !
So I was thinking how to make to tools to help game making and debuging.

This project is based on the Lua console from FRex (http://en.sfml-dev.org/forums/index.php?topic=15962), and its purpose is to be a python shell within SFML that will also automatically be linked with game objects for debugging / inspection etc.

How does it work?
- user creates a swig wrapper file telling swig what objects are to be exported from C++ to python (for instance, "Player" class, etc)
- a specific project is dedicated to building the python module (.pyd file) generated by swig, which exposes the game objects
- within the actual SFML game, I use the Python C Api to do several things. A python shell is loaded and is bound to the SFML Console for rendering and input, then the previous pyd module is imported so the shell has the knowledge of some C++ classes within Python. From the SFML app, the user can specify which instances of game objects can be in scope within the python shell. For insance in the picture I put the instance named "pl" of a C++ "Player" class, into the global python objects, so the C++ object can be directly manipulated through the python console

limitations
due to the input format of the console it's not really possible to input multi-line strings and tabulations, which is pretty bad since the scripting language is python. So it's not really possible to input new functions in the shell


I'll post the source code later if anyone is interested



FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: SFML Python console
« Reply #1 on: December 27, 2015, 06:15:48 am »
Quote
limitations
due to the input format of the console it's not really possible to input multi-line strings and tabulations, which is pretty bad since the scripting language is python. So it's not really possible to input new functions in the shell
You could save all the code in a string until you get an empty line and only then execute it.
Python interactive command line program does it that way.
And you can change tabulations into spaces or make them be 1 space wide in console or something.

And I like the idea of using my code with Python.
I was thinking that it'd be possible to make my console into a general purpose console that can be hooked to any interpreter and completer easily, but I'm very fine with just Lua so I didn't need that yet.
« Last Edit: December 27, 2015, 06:26:53 am by FRex »
Back to C++ gamedev with SFML in May 2023

lezebulon

  • Full Member
  • ***
  • Posts: 235
    • View Profile
Re: SFML Python console
« Reply #2 on: December 27, 2015, 01:38:32 pm »
indeed I just noticed that my python shell works as you described when I try to enter a function definition for instance.
However I have no idea how it's done, from the C-Api point of view. The command line that is sent to python C Api uses the flag Py_single_input , so that it evaluates in shell-mode and prints the last result statement in some case (like when I type 'a' and not when I type 'a=2'). I have no idea how to tell it that in some cases it should wait for an empty line before processing (because I don't want to have to type an extra empty line for all comands)

 

anything