Jump to content

  • Log In with Google      Sign In   
  • Create Account


"Use of Unregistered Class" + Luabind


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 c_fried_rice   Members   -  Reputation: 163

Like
0Likes
Like

Posted 02 February 2014 - 12:56 PM

Hey guys, 

 

I'm trying to convert my game engine's use of luabridge to luabind, and am running into a fairly large issue:

 

I get this error upon trying to transition to the "SongSelect" state:

 

 

std::runtime_error: 'Trying to use unregistered class'

 

Here's some of the C++ code calling the lua script:

SongSelect::Instance()->register_lua(L);

int error = luaL_loadfile(L, "Assets/Scripts/States/SongSelect.lua");

if (error)
{
	std::cout << lua_tostring(L, -1) << std::endl;
}

m_pGamestateManager->getStateMachine()->changeState(SongSelect::Instance());

if (lua_pcall(L, 0, 0, 0) != 0)
{
	std::cout<< " Error (in SM transition) "<< lua_tostring(L, -1) <<std::endl;
} 

Here's the registration of the Luabind Module:

void SongSelect::register_lua(lua_State* L)
{
	if (L != NULL)
	{
		luabind::module(L) [
			luabind::class_<SongSelect>("SongSelect")
			.scope[
					luabind::def("Instance", &SongSelect::Instance)
			]
				.def("init", &SongSelect::stateInit)
				.def("initSongs", &SongSelect::initSongs)
				.def("initAlbumArt", &SongSelect::initAlbumArt)
				.def_readwrite("bg", &SongSelect::bg)
				.def_readwrite("name", &SongSelect::name)
				.def_readwrite("font", &SongSelect::font)
				.def_readwrite("label", &SongSelect::label)
				.def_readwrite("artist", &SongSelect::artist_i)
				.def_readwrite("album_i", &SongSelect::album_i)
				.def_readwrite("title", &SongSelect::title_i)
				.def_readwrite("year", &SongSelect::year_i)
				.def_readwrite("genre", &SongSelect::genre_i)
				.def_readwrite("right", &SongSelect::right_i)
				.def_readwrite("left", &SongSelect::left_i)
				.def_readwrite("songs", &SongSelect::songs)
		];
	}
}
void Game::register_lua(lua_State* L)
{
	if (L != NULL)
	{
		luabind::module(L) [
				luabind::class_<Game>("Game")
					.scope[
						luabind::def("Instance", &Game::Instance)
					]
					.def_readwrite("title", &Game::title)
					.def_readwrite("x_pos", &Game::x)
					.def_readwrite("y_pos", &Game::y)
					.def_readwrite("width", &Game::width)
					.def_readwrite("height", &Game::height)
					.def_readwrite("fullscreen", &Game::fullscreen)
					.def_readwrite("font", &Game::font)
					.def_readwrite("label", &Game::label)
					.def("init", &Game::initialize),
				luabind::class_<Track>("Track")
					.def(luabind::constructor<>())
					.def_readwrite("music", &Track::music)
					.def_readwrite("midi", &Track::midi)
					.def_readwrite("title", &Track::title)
					.def_readwrite("artist", &Track::artist)
					.def_readwrite("genre", &Track::genre)
					.def_readwrite("album", &Track::album)
					.def_readwrite("album_art", &Track::album_art)
					.def_readwrite("year", &Track::year)
					.def_readwrite("bpm", &Track::bpm)
					.def_readwrite("l_track", &Track::left_track)
					.def_readwrite("r_track", &Track::right_track),
				luabind::class_<GameObject>("GameObject")
					.def(luabind::constructor<>())
					.def_readwrite("row", &GameObject::m_row)
					.def_readwrite("frame", &GameObject::m_frame)
					.def_readwrite("rows", &GameObject::m_rows)
					.def_readwrite("frames", &GameObject::m_frames)
					.def_readwrite("x", &GameObject::m_x)
					.def_readwrite("y", &GameObject::m_y)
					.def_readwrite("width", &GameObject::m_width)
					.def_readwrite("height", &GameObject::m_height)
					.def_readwrite("filename", &GameObject::m_filename)
					.def_readwrite("texture", &GameObject::m_texture)
					.def_readwrite("speed", &GameObject::m_speed)
					.def("init", &GameObject::init),
				luabind::class_<FXObject, GameObject>("FXObject")
					.def(luabind::constructor<>())
					.def_readwrite("x2", &FXObject::m_x2)
					.def_readwrite("y2", &FXObject::m_y2)
					.def_readwrite("xc", &FXObject::m_xc)
					.def_readwrite("yc", &FXObject::m_yc)
					.def_readwrite("scale", &FXObject::m_sscale)
					.def_readwrite("end_scale", &FXObject::m_escale)
					.def_readwrite("start_alpha", &FXObject::m_startalpha)
					.def_readwrite("start_alpha_f", &FXObject::m_startalpha_f)
					.def_readwrite("alpha", &FXObject::m_alpha)
					.def_readwrite("end_alpha", &FXObject::m_endalpha),
				luabind::class_<UIObject, GameObject>("UIObject")
					.def(luabind::constructor<>()),
				luabind::class_<UIAnimator, UIObject>("UIAnimator")
					.def(luabind::constructor<>()),
				luabind::class_<UIButton, UIObject>("UIButton")
					.def(luabind::constructor<>()),
				luabind::class_<StaticUI, UIObject>("StaticUI")
					.def(luabind::constructor<>())
					.def_readwrite("flip", &StaticUI::m_flip)
					.def_readwrite("alpha", &StaticUI::m_alpha)
					.def("init", &StaticUI::init)
		];
	}
}

Here's the lua script where the error is occurring:

-- SongSelect Properties
ssInstance = SongSelect.Instance();

ssInstance.name = "Song Select";
ssInstance.bg = "Assets/Art/Song Select/bg.png";

-- Artist Icon
ssInstance.artist = StaticUI();
ssInstance.artist.filename = "Assets/Art/Other/placeholder.png";
ssInstance.artist.texture = "Artist Icon";
ssInstance.artist.frames = 1
ssInstance.artist.rows = 1
ssInstance.artist.frame = 1
ssInstance.artist.row = 1
ssInstance.artist.x = 15;
ssInstance.artist.y = 415;
ssInstance.artist.width = 35
ssInstance.artist.height = 35
ssInstance.artist.speed = 1;
ssInstance.artist.flip = false;
ssInstance.artist.alpha = 255;

ssInstance.artist:init(ssInstance.artist.x, ssInstance.artist.y,
  ssInstance.artist.width, ssInstance.artist.height,
  ssInstance.artist.filename, ssInstance.artist.texture, ssInstance.artist.flip);

-- Album Icon
ssInstance.album_i = StaticUI();
ssInstance.album_i.filename = "Assets/Art/Other/placeholder.png";
ssInstance.album_i.texture = "Album Icon";
ssInstance.album_i.frames = 1
ssInstance.album_i.rows = 1
ssInstance.album_i.frame = 1
ssInstance.album_i.row = 1
ssInstance.album_i.x = 15;
ssInstance.album_i.y = 450;
ssInstance.album_i.width = 35
ssInstance.album_i.height = 35
ssInstance.album_i.speed = 1;
ssInstance.album_i.flip = false;
ssInstance.album_i.alpha = 255;

ssInstance.album_i:init(ssInstance.album_i.x, ssInstance.album_i.y,
  ssInstance.album_i.width, ssInstance.album_i.height,
  ssInstance.album_i.filename, ssInstance.album_i.texture, ssInstance.album_i.flip);

-- Title Icon
ssInstance.title = StaticUI();
ssInstance.title.filename = "Assets/Art/Other/placeholder.png";
ssInstance.title.texture = "Title Icon";
ssInstance.title.frames = 1
ssInstance.title.rows = 1
ssInstance.title.frame = 1
ssInstance.title.row = 1
ssInstance.title.x = 15;
ssInstance.title.y = 485;
ssInstance.title.width = 35
ssInstance.title.height = 35
ssInstance.title.speed = 1;
ssInstance.title.flip = false;
ssInstance.title.alpha = 255;


ssInstance.title:init(ssInstance.title.x, ssInstance.title.y,
  ssInstance.title.width, ssInstance.title.height,
  ssInstance.title.filename, ssInstance.title.texture, ssInstance.title.flip);


-- Year Icon
ssInstance.year = StaticUI();
ssInstance.year.filename = "Assets/Art/Other/placeholder.png";
ssInstance.year.texture = "Year Icon";
ssInstance.year.frames = 1
ssInstance.year.rows = 1
ssInstance.year.frame = 1
ssInstance.year.row = 1
ssInstance.year.x = 15;
ssInstance.year.y = 520;
ssInstance.year.width = 35
ssInstance.year.height = 35
ssInstance.year.speed = 1;
ssInstance.year.flip = false;
ssInstance.year.alpha = 255;


ssInstance.year:init(ssInstance.year.x, ssInstance.year.y,
  ssInstance.year.width, ssInstance.year.height,
  ssInstance.year.filename, ssInstance.year.texture, ssInstance.year.flip);


-- Genre Icon
ssInstance.genre = StaticUI();
ssInstance.genre.filename = "Assets/Art/Other/placeholder.png";
ssInstance.genre.texture = "Genre Icon";
ssInstance.genre.frames = 1
ssInstance.genre.rows = 1
ssInstance.genre.frame = 1
ssInstance.genre.row = 1
ssInstance.genre.x = 15;
ssInstance.genre.y = 555;
ssInstance.genre.width = 35
ssInstance.genre.height = 35
ssInstance.genre.speed = 1;
ssInstance.genre.flip = false;
ssInstance.genre.alpha = 255;


ssInstance.genre:init(ssInstance.genre.x, ssInstance.genre.y,
  ssInstance.genre.width, ssInstance.genre.height,
  ssInstance.genre.filename, ssInstance.genre.texture, ssInstance.genre.flip);

-- Right Track Icon
ssInstance.right = StaticUI();
ssInstance.right.filename = "Assets/Art/Other/placeholder.png";
ssInstance.right.texture = "Right Icon";
ssInstance.right.frames = 1
ssInstance.right.rows = 1
ssInstance.right.frame = 1
ssInstance.right.row = 1
ssInstance.right.x = 15;
ssInstance.right.y = 590;
ssInstance.right.width = 35
ssInstance.right.height = 35
ssInstance.right.speed = 1;
ssInstance.right.flip = false;
ssInstance.right.alpha = 255;


ssInstance.right:init(ssInstance.right.x, ssInstance.right.y,
  ssInstance.right.width, ssInstance.right.height,
  ssInstance.right.filename, ssInstance.right.texture, ssInstance.right.flip);


-- Left Track Icon
ssInstance.left = StaticUI();
ssInstance.left.filename = "Assets/Art/Other/placeholder.png";
ssInstance.left.texture = "Left Icon";
ssInstance.left.frames = 1
ssInstance.left.rows = 1
ssInstance.left.frame = 1
ssInstance.left.row = 1
ssInstance.left.x = 15;
ssInstance.left.y = 625;
ssInstance.left.width = 35
ssInstance.left.height = 35
ssInstance.left.speed = 1;
ssInstance.left.flip = false;
ssInstance.left.alpha = 255;


ssInstance.left:init(ssInstance.left.x, ssInstance.left.y,
  ssInstance.left.width, ssInstance.left.height,
  ssInstance.left.filename, ssInstance.left.texture, ssInstance.left.flip);

-- FONTS
ssInstance.font = "Assets/Fonts/ostrich-bold.ttf";
ssInstance.label = "ostrich16";

-- Init Songs
ssInstance:initSongs();

ssInstance:initAlbumArt(ssInstance.songs);

ssInstance:init();

Can anyone tell me what I'm doing wrong?

 

Thanks!



Sponsor:

#2 c_fried_rice   Members   -  Reputation: 163

Like
0Likes
Like

Posted 02 February 2014 - 06:27 PM

Apologies for the double post, but it appears the problem lies in the use of std::vector<Track>. However I can't seem to properly register a std::vector<Track> in Luabind. 

 

I tried following the example in the luabind documentation (which admittedly is prettttty old at this stage) located here.

 

Anyone got any suggestions?



#3 Mnemotic   Members   -  Reputation: 298

Like
0Likes
Like

Posted 03 February 2014 - 07:05 AM

OT

 

Out of curiousity, why did you decide to switch from LuaBridge to luabind?






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS