Jump to content

[C++] Custom lua functions crashed in LE editor?


Guppy
 Share

Recommended Posts

Disclaimer: It's getting a bit late so maybe I'm missing something obvious

 

I've been trying to figure out the Interpreter class and how to create custom lua functions, and it's going well quite apart from not being able to identify a register function on the interpreter class - so I cheated a bit there.

 

static int addTwo(lua_State *L){
   int argc=Interpreter::GetStackSize(); // equiv to lua_gettop(Interpreter::L) ?
   int i,t;
   for (i = 1; i <= argc; i++){
       t=Interpreter::ToNumber(i);
       std::cout << "[C++]addTwo(" << t << ")=" << (t+2) << std::endl;
       Interpreter::PushFloat(t+2);
   }

   return i-1;
}

 

and in App::Start()

lua_register(Interpreter::L,"addTwo",addTwo);

 

In the fps player controller i added this

a,b,c=addTwo(1,2,3)
System:Print(a)
System:Print(B)
System:Print(c)

to the pickup code rigth after "mass = pickInfo.entity:GetMass()" to make sure I can trigger it when ever I want.

 

Now the strange bit is this works perfectly in Code::blocks - but by when I run it in the LE editor it instantly crashed when I try to pick something up.

 

 

I've tried toggling sandbox to no avail

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

Initialize it first like this before map is loaded (if you load any)

if (Interpreter::L == NULL) Interpreter::Reset();

 

Also your lua script has a typo, capital B instead of b.

 

It works on windows atleast both in editor and not.

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

The capital b seems to be a paste error, I added the reset line just before loading the the start map and much as I suspected it made no difference ( being called from a script being run by the Interpreter the Interpreter should be initialized ).

 

The most annoying bit is there is no indication of why it stops it just exits with "Error: Unkown client disconnected"

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

Link to comment
Share on other sites

but in a brand new project it doesn't happen ... :| time to delete code untill it stops happening I guess

 

Well this was embarasing - somehow ( and I swear I've not changed it ) the debug build target lost the ".debug" extension so the LE editor was using an old version every time I hit debug.

 

The crash you ask? well that is aparently how LE handles unkown functions - would have been really nice to get an error tbh.

System:

Linux Mint 17 ( = Ubuntu 14.04 with cinnamon desktop ) Ubuntu 14.04, AMD HD 6850, i5 2500k

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...