Advertisement

Luaplus and classes

Started by March 19, 2004 04:52 PM
-1 comments, last by Alura 20 years, 8 months ago
Well, i mainly got lua plus due to the fact that it had a friendly way to use classes, anyway, i've been having some problems with it, i'll explain: Here's my source on vc++:

#pragma comment(lib, "LuaPlus_1081.lib")

#include <stdio.h>
#include <LuaPlus/LuaPlus.h>
#include <tchar.h>
#include <conio.h>

LuaStateOwner LUA;
int test(LuaState* luaVM);

class Poo {
public:
	float pooer;
	float Pooey(float tester)
	{
		pooer = 1.0f;
		pooer = 1.0f/tester;
		return pooer;
	}

	void Hex(LuaState* luaVM)
	{
		LuaStack args(luaVM);
		pooer = 1.0f/args[1].GetNumber();
		printf("%f\n",pooer);
		LUA->PushNumber(pooer);
	}

	Poo()
	{
		pooer = 1.0f;
	}
};

int test(LuaState* luaVM)
{
	LuaStack args(luaVM);
	if(args[1].IsNumber())
	{
		float y = args[1].GetNumber();
		float yes = 1.0f/y;
		LUA->PushNumber(0);
		printf("%f\n",yes);
	}
	return 1;
}

int main(int argc, _TCHAR* argv[])
{	
	Poo Shitos;

	LUA->GetGlobals().Register("Test", &test);
	LUA->GetGlobals().Register("Indirect", Shitos, Poo::Hex);
	LUA->GetGlobals().RegisterDirect("Direct", Shitos, Poo::Pooey);

	LUA->DoFile("startup.lua");

	printf("%f",Shitos.pooer);

	getch();

	return 0;
}
And then in the startup.lua file i have:

print('Normal:');
Test(4.0);
print('Direct member:');
x = Direct(4.0);
print(x);
print('Indirect member:');
x = Indirect(4.0);
print(x);
The problem is that it gives me an error when i compile the c++ file, it says that it can't convert from class Poo to lua_CFunction, am i doing anything wrong? And if so, how to fix it? NOTE: This occurs when i try to use any of the register functions. [edited by - Alura on March 21, 2004 11:01:16 AM]

This topic is closed to new replies.

Advertisement