Jump to content

Recommended Posts

Posted

How to call a script "lua" in C language?

 

i like to execute "start.lua" in my main() like this:

 

main(..)
{
....
luahandle=loadscripte("main.lua");
executescript( luahandle);
...
}

 

why LE removed in "engine.cpp" the function : ( leLoadScript, leRunScript, leFreeScript) ?

 

thanks

 

PS: i work with LE2.5.

Posted

Just download the Lua library, include it in your project, and call the Lua functions directly.

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

If at any time you want to mix LE's lua_State variable you will need to use LuaJIT (because that's what LE uses) or you'll have issues. If you don't plan on mixing then you can use whatever version you want, but I'd use the latest.

Posted

Hello Rick

 

Oh ok, I thought that was very fast for a language interpreted, is is a JIT compiler, now I can die in peace lol;-)

 

I was on their site and it offers several versions:

 

LuaJIT beta-2

LuaJIT-1.1.7

LuaJIT-1.1.6

LuaJIT-1.1.5

LuaJIT-1.1.4

LuaJIT-1.1.3

LuaJIT-1.1.2

LuaJIT-1.1.0

LuaJIT-1.0.3

 

what is the version with which LE was compiled?

 

Tthank Great Rick ;-)

Posted

I use LuaJIT-1.1.6

 

You can just include the source files into your C++ project.

 

 

I do not understand, you have only included the *. c and h * in your project?

you must generate Lu51.dll and Lu51.lib to include in the project, otherwise I do not see how linking'll be able to find references?

 

I compiled LuaJit in a separate project. For those who would try without success. It is essential to add to the compilation directive the two following define: LUA_BUILD_AS_DLL and LUA_LIB in the definition of the preprocessor section.

 

I have lua51.dll Lua51.lib and after compilation. I have include in my project.

 

I tried the following code but it does not work?

luaL_loadfile ((* lua_State) GetLuaState (), "toto.lua");
lua_pcall ((* lua_State) GetLuaState (), 0, LUA_MULTRET, 0);

 

And in my toto.lua

 

Notify("Greate it work");

 

If you have an idea I'm interested;-)

 

Gabriel

lua51.rar

Posted

Did you try giving an absolute path to the script? Not sure if Lua uses relative paths.

 

 

I do not understand, you have only included the *. c and h * in your project?

you must generate Lu51.dll and Lu51.lib to include in the project, otherwise I do not see how linking'll be able to find references?

 

The .c and .h files is the Lua source. You can either do what you did and make the dll's or you can just include the source directly into your own exe.

Posted

my methode Execute

 

	void Execute(const char*script)
	{
		//lua_State *L = (lua_State*)GetLuaState();
		lua_State *L = reinterpret_cast<lua_State*> (GetLuaState());

		if (luaL_loadfile(L, script) || lua_pcall(L, 0, 0, 0))
		{
			char szTmp[255];
			sprintf(szTmp,"err:: %s",lua_tostring(L, -1));
			MessageBox(NULL, szTmp,"error in MontanaHorse.exe",MB_OK);
		}
	}

 

yes a try with absolute and relative paths, but same responce "err: attempt to call a string value"

 

please HELLLLLPPPP ME lol ;-)

Posted

after debugging step by step in lua, that's the solution I without changing the source code of lua or LeadWerks.

 

void Execute(const char*script)
{
static bool Dunny=false;
int iStatus;

if (!Dunny)
{
	Dunny=true;
	iStatus = luaL_loadstring( (lua_State*)m_entity, "" ); // call only first time !!!
}

iStatus = luaL_loadfile( (lua_State*)m_entity, script );
if (iStatus)
{         
	char szTmp[255];
	sprintf(szTmp,"Error @LoadFile: %s",lua_tostring((lua_State*)m_entity, -1));
	MessageBox(NULL, szTmp,"error in MontanaHorse.exe",MB_OK);
	return ;     
}      

iStatus = lua_pcall( (lua_State*)m_entity, 0, 0, 0); //this might be to initialise the lua script     

if( iStatus )     
{         
	char szTmp[255];
	sprintf(szTmp,"Error @pcall: %s",lua_tostring((lua_State*)m_entity, -1));
	MessageBox(NULL, szTmp,"error in MontanaHorse.exe",MB_OK);
	return ;     
}
}

 

I agree with you it's not very conventional, but it works.

I will not get lost in debates where the bug;-)

 

what I saw with the debug, after the first call to the luaL_loadfile stack is empty and only after the second call of luaT_loadfile the stack has a function.

 

Here it works and I'm happy.

 

Gabriel

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...