any active irrlicht scripting projects?

Discuss about anything related to the Irrlicht Engine, or read announcements about any significant features or usage changes.
Post Reply
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

any active irrlicht scripting projects?

Post by xDan »

Hi,

Are there any *active* script bindings? Most listed on the irrlicht links page seem to be inactive and based on much older Irrlicht versions.

Preferably one in a C style language...

:shock:

I'm fed up with C++ :x back when I used to make 2D games in a script language I actually finished stuff :cry:
sudi
Posts: 1686
Joined: Fri Aug 26, 2005 8:38 pm

Post by sudi »

Well i'm working on a squirrel binding.
but squirrel is not c-style...
We're programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We're not excited by renovation:tinkering,improving,planting flower beds.
stevend
Posts: 114
Joined: Sat Mar 01, 2008 7:18 pm

Post by stevend »

Well, im not so sure about an actual irrlicht binding

but you could use Lua with Luna (a cpp binding for lua) and interface your lua scripts with a C++ class. You could then call members functions of your own class. Might not be exactly what you looking for, but it helped me.


for usage and example code:
http://lua-users.org/wiki/SimplerCppBinding

Code: Select all

extern "C" {
#include "lua.h"
#include "lauxlib.h"
}

template <typename T> class Luna {
  typedef struct { T *pT; } userdataType;
public:
  typedef int (T::*mfp)(lua_State *L);
  typedef struct { const char *name; mfp mfunc; } RegType;

  static void Register(lua_State *L) {
    lua_newtable(L);
    int methods = lua_gettop(L);

    luaL_newmetatable(L, T::className);
    int metatable = lua_gettop(L);

    // store method table in globals so that
    // scripts can add functions written in Lua.
    lua_pushstring(L, T::className);
    lua_pushvalue(L, methods);
    lua_settable(L, LUA_GLOBALSINDEX);

    lua_pushliteral(L, "__metatable");
    lua_pushvalue(L, methods);
    lua_settable(L, metatable);  // hide metatable from Lua getmetatable()

    lua_pushliteral(L, "__index");
    lua_pushvalue(L, methods);
    lua_settable(L, metatable);

    lua_pushliteral(L, "__tostring");
    lua_pushcfunction(L, tostring_T);
    lua_settable(L, metatable);

    lua_pushliteral(L, "__gc");
    lua_pushcfunction(L, gc_T);
    lua_settable(L, metatable);

    lua_newtable(L);                // mt for method table
    int mt = lua_gettop(L);
    lua_pushliteral(L, "__call");
    lua_pushcfunction(L, new_T);
    lua_pushliteral(L, "new");
    lua_pushvalue(L, -2);           // dup new_T function
    lua_settable(L, methods);       // add new_T to method table
    lua_settable(L, mt);            // mt.__call = new_T
    lua_setmetatable(L, methods);

    // fill method table with methods from class T
    for (RegType *l = T::methods; l->name; l++) {
    /* edited by Snaily: shouldn't it be const RegType *l ... ? */
      lua_pushstring(L, l->name);
      lua_pushlightuserdata(L, (void*)l);
      lua_pushcclosure(L, thunk, 1);
      lua_settable(L, methods);
    }

    lua_pop(L, 2);  // drop metatable and method table
  }

  // get userdata from Lua stack and return pointer to T object
  static T *check(lua_State *L, int narg) {
    userdataType *ud =
      static_cast<userdataType*>(luaL_checkudata(L, narg, T::className));
    if(!ud) luaL_typerror(L, narg, T::className);
    return ud->pT;  // pointer to T object
  }

private:
  Luna();  // hide default constructor

  // member function dispatcher
  static int thunk(lua_State *L) {
    // stack has userdata, followed by method args
    T *obj = check(L, 1);  // get 'self', or if you prefer, 'this'
    lua_remove(L, 1);  // remove self so member function args start at index 1
    // get member function from upvalue
    RegType *l = static_cast<RegType*>(lua_touserdata(L, lua_upvalueindex(1)));
    return (obj->*(l->mfunc))(L);  // call member function
  }

  // create a new T object and
  // push onto the Lua stack a userdata containing a pointer to T object
  static int new_T(lua_State *L) {
    lua_remove(L, 1);   // use classname:new(), instead of classname.new()
    T *obj = new T(L);  // call constructor for T objects
    userdataType *ud =
      static_cast<userdataType*>(lua_newuserdata(L, sizeof(userdataType)));
    ud->pT = obj;  // store pointer to object in userdata
    luaL_getmetatable(L, T::className);  // lookup metatable in Lua registry
    lua_setmetatable(L, -2);
    return 1;  // userdata containing pointer to T object
  }

  // garbage collection metamethod
  static int gc_T(lua_State *L) {
    userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
    T *obj = ud->pT;
    delete obj;  // call destructor for T objects
    return 0;
  }

  static int tostring_T (lua_State *L) {
    char buff[32];
    userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
    T *obj = ud->pT;
    sprintf(buff, "%p", obj);
    lua_pushfstring(L, "%s (%s)", T::className, buff);
    return 1;
  }
};
bitplane
Admin
Posts: 3204
Joined: Mon Mar 28, 2005 3:45 am
Location: England
Contact:

Post by bitplane »

Kind of on topic for this thread, although I'm quite sure nobody has done it yet...

Google's V8 JavaScript VM is BSD licensed, is embeddable and actually compiles to machine code, it's supposed to be lightning fast too.

http://code.google.com/apis/v8/
Submit bugs/patches to the tracker!
Need help right now? Visit the chat room
stevend
Posts: 114
Joined: Sat Mar 01, 2008 7:18 pm

Post by stevend »

Kind of on topic for this thread, although I'm quite sure nobody has done it yet...

Google's V8 JavaScript VM is BSD licensed, is embeddable and actually compiles to machine code, it's supposed to be lightning fast too.

http://code.google.com/apis/v8/
wow, this is cool

also did not know that chrome is open source.

good job google.
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Wow, yes I like JS. If I go the DIY binding route I will look into V8.

I'd be interested in seeing a squirrel binding if it got finished and was kept updated :P Are you near completing it?

Although I do prefer C style.

There's already a IrrLua binding, but I think that's like Irrlicht 1.1 or something.

If there's no actualy active and finished projects I'll probably do something myself :S
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

V8's documentation (at a brief glance) seems very good. That is a killer feature for me!
Frank Dodd
Posts: 208
Joined: Sun Apr 02, 2006 9:20 pm

Post by Frank Dodd »

I am still keeping my IrrlichtWrapper going, it integrates with FreeBasic and you can find the link by clicking here

It exposes a lot of the engine and is very simple to use, it currently uses Irrlicht 1.4 although there is a beta at the end of the thread that uses 1.4.1
xDan
Competition winner
Posts: 673
Joined: Thu Mar 30, 2006 1:23 pm
Location: UK
Contact:

Post by xDan »

Cool, I'll look into that 8)
JRowe47
Posts: 55
Joined: Sat Jun 30, 2007 9:09 am

Post by JRowe47 »

A.Percy has made some great progress in adapting irrlicht for AutoIt. Granted, it restricts you to windows, or running under Wine, but that's not too bad, especially for the ease of use. AutoIt is incredibly simple to use.

http://www.autoitscript.com/forum/index ... opic=70506

There's some integration issues, as there are array problems with AutoIt's plugin architecture, but there will be a workaround soon. Anyway, it makes things easy, so far. Just need some more interested folks. :)
init512
Posts: 18
Joined: Mon Mar 26, 2007 6:08 pm
Contact:

Script bindings for Irrlicht

Post by init512 »

Hey xDan,

I am using Lua for scripting in my project, and I have modified the Pyrr bindings definition file for SWIG (the program that I use to generate bindings) to work with Lua on 1.4.2. I don't have any documentation, but here is the binding file if you want to mess with it:

Code: Select all

%module(directors="1") irrlua

%{
#include "irrlicht.h"
#include "IImageLoader.h"
#include "IImageWriter.h"

using namespace irr;
using namespace core;
using namespace gui;
using namespace io;
using namespace scene;
using namespace video;
%}

%ignore operator[];

// 1.3 missing references
%ignore irr::video::SColorHSL::setfromRGB;
%ignore irr::gui::ICursorControl::setPosition(f32,f32);


%include IrrCompileConfig.h
%include irrTypes.h
%include IReferenceCounted.h

%include typemaps.i
%include std_string.i

%{
#include <stdlib.h>
#include <wchar.h>
%}

%typemap( in, checkfn="lua_isstring" ) wchar_t* (int temp_len)
%{
    temp_len = lua_strlen( L, $input );
    $1 = new wchar_t[temp_len * 2];
    mbstowcs( $1, lua_tostring( L, $input ), temp_len );
    $1[temp_len] = 0;
%}

%typecheck(SWIG_TYPECHECK_STRING) wchar_t* {
 $1 = lua_isstring(L,$input);
}

%typemap( freearg ) wchar_t*
%{
    delete [] $1;
%}

%typemap( out ) wchar_t* (int temp_len, char* temp_str)
%{
    temp_len = wcslen($1);
    temp_str = new char[temp_len];
    wcstombs(temp_str, $1, temp_len);
    lua_pushlstring(L, temp_str, temp_len);
    SWIG_arg++;
%}

/*
%include irrArray.h
%include irrMap.h
*/

%include vector3d.h
%template(vector3df) irr::core::vector3d<irr::f32>;

%include line3d.h
%include plane3d.h
%include aabbox3d.h
%template(aabbox3df) irr::core::aabbox3d<irr::f32>;

%include SColor.h
%include SLight.h

%include dimension2d.h
%template(dimension2df) irr::core::dimension2d<irr::f32>;
%template(dimension2di) irr::core::dimension2d<irr::s32>;

%include position2d.h
%template(position2di) irr::core::position2d<irr::s32>;

%include rect.h
%template(recti) irr::core::rect<irr::s32>;

%include EDriverTypes.h

%include ICursorControl.h


/*
%include heapsort.h
%include IAttributes.h
*/
%include IAttributeExchangingObject.h


%feature("director") irr::IEventReceiver;
%feature("director") irr::IEventReceiver::OnEvent;
%include IEventReceiver.h

%include ESceneNodeAnimatorTypes.h
%include ISceneNodeAnimator.h
%include ESceneNodeTypes.h
%include ITriangleSelector.h


%include Keycodes.h
//%include SKeyMap.h

%extend irr::SEvent {
   int getKeyInputChar() {return self->KeyInput.Char;};
   irr::EKEY_CODE getKeyInputKey() {return self->KeyInput.Key;};
   bool isKeyInputPressedDown() {return self->KeyInput.PressedDown;};
   bool isKeyInputShift() {return self->KeyInput.Shift;};
   bool isKeyInputCtrl() {return self->KeyInput.Control;};

   s32 getMouseInputX() {return self->MouseInput.X;};
   s32 getMouseInputY() {return self->MouseInput.Y;};
   f32 getMouseInputWheel() {return self->MouseInput.Wheel;};
   irr::EMOUSE_INPUT_EVENT getMouseInputEvent() {return self->MouseInput.Event;};

   irr::gui::IGUIElement* getGUIEventCaller() {return self->GUIEvent.Caller;};
   //irr::gui::IGUIScrollBar* getGUIEventCallerScrollBar() {return (irr::gui::IGUIScrollBar*)(self->GUIEvent.Caller);};
   gui::EGUI_EVENT_TYPE getGUIEventType() {return self->GUIEvent.EventType;};

	const c8* getLogEventText() {return self->LogEvent.Text;};
	irr::ELOG_LEVEL getLogEventLevel() {return self->LogEvent.Level;};

	s32 getUserEventData1() {return self->UserEvent.UserData1;};
	s32 getUserEventData2() {return self->UserEvent.UserData2;};
}


%include ETerrainElements.h
%include ISceneManager.h

%feature("director") irr::scene::ISceneNode;
%feature("director") irr::scene::ISceneNode::OnRegisterSceneNode;
%feature("director") irr::scene::ISceneNode::OnAnimate;
%feature("director") irr::scene::ISceneNode::render;
%feature("director") irr::scene::ISceneNode::getBoundingBox;
%feature("director") irr::scene::ISceneNode::getMaterialCount;

%feature("director") irr::scene::ISceneNode::OnReadUserData;
%feature("director") irr::scene::ISceneNode::createUserData;
%feature("nodirector") irr::scene::ISceneNode::setName;
%feature("nodirector") irr::scene::ISceneNode::getName;

%feature("nodirector") irr::scene::ISceneNode::getMaterial;
%feature("nodirector") irr::scene::ISceneNode::getTriangleSelector;

%include ISceneNode.h

%include IMeshBuffer.h
%include IMesh.h

%include IAnimatedMesh.h
%include IAnimatedMeshMD2.h

%include IShadowVolumeSceneNode.h
%include IAnimatedMeshMD3.h
/*
%include IAnimatedMeshMS3D.h
%include IAnimatedMeshMS3D.h
%include IQ3LevelMesh.h
%include IAnimatedMeshX.h
%include IAnimatedMeshB3d.h
*/
%include IAnimatedMeshSceneNode.h

/*
%include ICameraSceneNode.h
%include IDummyTransformationSceneNode.h
%include IFileList.h
%include IFileSystem.h
%include IGUICheckBox.h
%include IGUIContextMenu.h
%include IGUIComboBox.h
%include IGUIEditBox.h
*/
%include IXMLReader.h
%include IFileSystem.h

%include EGUIElementTypes.h
%include IGUIElement.h


%feature("compactdefaultargs") irr::gui::addStaticText;

%include IGUIButton.h
%include IGUISkin.h
%include IGUIWindow.h
%include IGUIEnvironment.h

/*
%include IGUIFileOpenDialog.h
%include IGUIColorSelectDialog.h
%include IGUIFont.h
%include IGUIFontBitmap.h
%include IGUIImage.h
%include IGUIInOutFader.h
%include IGUIListBox.h
%include IGUIMeshViewer.h
%include IGUIScrollBar.h
%include IGUIStaticText.h
%include IGUITabControl.h
%include IGUIToolbar.h
%include ILightSceneNode.h
*/

%include ILogger.h


/*
%include IMeshCache.h
%include IMeshSceneNode.h
%include IMeshManipulator.h
%include IMetaTriangleSelector.h
%include IReadFile.h
*/

%include IOSOperator.h
%include ITimer.h
%include IrrlichtDevice.h

/*
%include irrMath.h
%include irrString.h
*/


/*
%include IAttributes.h
%include ISceneUserDataSerializer.h
%include ISceneCollisionManager.h
%include IMaterialRendererServices.h
%include ISceneNodeFactory.h
%include ISceneNodeAnimatorFactory.h
%include ISceneNodeAnimatorCollisionResponse.h
%include IShaderConstantSetCallBack.h
%include IParticleSystemSceneNode.h
%include ITerrainSceneNode.h
%include ITextSceneNode.h
%include IParticleEmitter.h
%include IParticleAffector.h
%include IBillboardSceneNode.h
*/

%include ECullingTypes.h
%include EMaterialFlags.h
%include EMaterialTypes.h
%include S3DVertex.h
%include SMaterial.h
%include IMaterialRenderer.h
%include ITexture.h

%include SExposedVideoData.h
%include IGPUProgrammingServices.h

%include IImage.h
%include IImageLoader.h
%include IImageWriter.h
%include IVideoDriver.h

/*
%include IVideoModeList.h
%include IWriteFile.h
%include IXMLWriter.h
%include line2d.h
%include line3d.h
%include irrList.h
%include matrix4.h
%include plane3d.h
%include vector2d.h
*/


/*
%include triangle3d.h
%include quaternion.h
*/

/*
%include SAnimatedMesh.h
*/

/*
%include SMesh.h
%include SMeshBuffer.h
%include SMeshBufferLightMap.h
%include SMeshBufferTangents.h
%include SViewFrustum.h
%include coreutil.h
*/

%include SIrrCreationParameters.h

////////////////////////////////////////////////////////////
It works for me, you can generate a library to link with your code like so:

(This is from memory, maybe there is a mistake :) )

Code: Select all

swig -c++ -lua -cpperraswarn -I./irrlicht-1.4.2/include -o ./src/irrlua_bindings.cxx ./src/lua/irrlua.i
g++ -I./irrlicht-1.4.2/include -I./lua/include -c -o irrlua_bindings.o ./src/irrlua_bindings.cxx
And if you want to create a nice library:

ar rs libirrlua.a irrlua_bindings.o

You will have to link your code with this library, Irrlicht (of course), and the Lua library, liblua. If you don't know what's going on, look at the documentation for Swig and Lua. You would do something like this to load the bindings into the Lua VM:

Code: Select all

extern "C" int luaopen_irrlua(lua_State* L);
...
luaopen_irrlua(L);
Enjoy, and give me and the Pyrr team some credit if you use it in your application.
Post Reply