The above video goes away if you are a member and logged in, so log in now!
[CPP] Luabind
This is a discussion on [CPP] Luabind within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Luabind
What:A small lib to simplify binding CPP classes to lua.
Who:jparishy
Spoiler for Readme :
Code:
This is a ...
Luabind
What:A small lib to simplify binding CPP classes to lua.
Who:jparishy
Spoiler for Readme:
Code:
This is a copy of Luabind revision 1.26.2.5 from the SVN ported to the Sony PSP.
Luabind is under the MIT License.
What is Luabind?
----------------
Luabind is the best library available for exporting C and C++ code to the lua interpretor, and vice versa.
I've tried all of the competitors, and nothing beats Luabind's awesomeness.
Dependencies:
-------------
Boost4PSP - http://boost4psp.sourceforge.net/
Lua - svn://svn.ps2dev.org/psp/trunk/lua
You will need to install both of the above for Luabind to work.
Install:
--------
After installing the Dependencies (see above), go into the luabind directory (The one with Makefile.PSP in it),
and type "make -f Makefile.PSP" to build the library, then "make -f Makefile.PSP install" to install it. You can clean the directory by
doing "make -f Makefile.PSP clean".
Samples:
--------
There is a sample in the examples/PSP folder. Just type "make" to build it.
Happy Coding!
-Julius Parishy
Copyright (C) The Luabind Team
http://www.rasterbar.com/products/luabind.html
Spoiler for Example:
Code:
// Minimal Luabind test on the PSP.
// Loads a luafile named 'test.lua'
// and uses the class 'Test' which is
// exported to lua.
//
// Copyright (C) 2008 Julius Parishy
#include <iostream>
#include <string>
using namespace std;
#include <luabind/luabind.hpp>
#include <lua.hpp>
#include <pspkernel.h>
PSP_MODULE_INFO("Luabind Test", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
class Test
{
private:
std::string m_string;
public:
Test(const std::string& str) : m_string(str) { }
~Test() { }
void print() { std::cout << m_string << "\n"; }
};
int main(int argc, char** argv)
{
lua_State* luaMain = lua_open();
luaL_openlibs(luaMain);
luabind::open(luaMain);
luabind::module(luaMain)
[
luabind::class_<Test>("Test")
.def(luabind::constructor<const std::string&>())
.def("print", &Test::print)
];
int err = luaL_loadfile(luaMain, "test.lua");
if(!err)
{
err = lua_pcall(luaMain, 0, LUA_MULTRET, 0);
if(err)
{
std::cout << "Lua encountered an error. \"" << lua_tostring(luaMain, -1) << "\n";
}
}
lua_close(luaMain);
return 0;
}