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...
![Shocked :shock:](./images/smilies/icon_eek.gif)
I'm fed up with C++
![Mad :x](./images/smilies/icon_mad.gif)
![Crying or Very sad :cry:](./images/smilies/icon_cry.gif)
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;
}
};
wow, this is coolKind 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/
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
////////////////////////////////////////////////////////////
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
Code: Select all
extern "C" int luaopen_irrlua(lua_State* L);
...
luaopen_irrlua(L);