Jump to content

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


Gabriel
 Share

Recommended Posts

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.

Link to comment
Share on other sites

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 ;-)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ;-)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...