Page 1 of 1

[0.9] Require crash

Posted: Wed Feb 26, 2014 12:55 pm
by rk84
Game crashes if I try to require file via console.

Re: [0.9] Require crash

Posted: Wed Feb 26, 2014 1:03 pm
by AlexPhoenix
Where file is placed?
and how exactly you requare file?

Re: [0.9] Require crash

Posted: Wed Feb 26, 2014 1:42 pm
by rk84
AlexPhoenix wrote:Where file is placed?
and how exactly you requare file?
1)Right next to factorio.exe
filename test.lua

2)require "test"

Also. I just noticed I use 32 bit zip package (usb memory stick) in 64 bit Win 7. Seems to work fine overall.

Re: [0.9] Require crash

Posted: Wed Feb 26, 2014 7:34 pm
by kovarex
So I fixed it, it returns error message instead of the crash.

Re: [0.9] Require crash

Posted: Mon Mar 03, 2014 8:14 am
by rk84
I would like to add that remote calling this also cause a crash.

Code: Select all

remote.addinterface("console++",
{
  test = function()
    return require("test")
  end
})
test.lua were in both, Win32 and mod's folder.
test.lua: creates local table, adds some functions to table and returns the table.

Re: [0.9] Require crash

Posted: Tue Mar 04, 2014 2:39 pm
by cube
rk84 wrote:I would like to add that remote calling this also cause a crash.

Code: Select all

remote.addinterface("console++",
{
  test = function()
    return require("test")
  end
})
test.lua were in both, Win32 and mod's folder.
test.lua: creates local table, adds some functions to table and returns the table.
Thanks for noticing. These corner cases are pretty annoying :-) Do you know if this worked in 0.8.x?

Re: [0.9] Require crash

Posted: Tue Mar 04, 2014 3:10 pm
by rk84
cube wrote:Do you know if this worked in 0.8.x?
I get console message in 0.8.8

Code: Select all

Cannot execute command. Error: attempt to index a string value

Re: [0.9] Require crash

Posted: Wed Mar 05, 2014 9:51 am
by cube
So I checked it now -- After kovarex's change the crash disappeared even with the remote.call scenario. On the other hand when remote.call was used from a mod, requires used in the interface would almost never work as intended. So I changed the error message and completely disabled requires in interfaces for 0.9.2

Re: [0.9] Require crash

Posted: Wed Mar 05, 2014 1:25 pm
by rk84
This is starting to be more of interface bug report than require, but still I will continue here.

there is problem when returning function(s) in interface. I remote call these in console. Returning number or string or number/string in table works, but functions do not.

This gives error "attempt to index a string value"

Code: Select all

test = function()
  return {function() game.player.print("functest") end}
end
This returns string "test"

Code: Select all

test = function()
  return function() game.player.print("functest") end
end

Re: [0.9] Require crash

Posted: Wed Mar 05, 2014 1:29 pm
by AlexPhoenix
from https://forums.factorio.com/wiki/inde ... interfaces
The interface functions can take only primitive types and tables as variables. The same holds for return values. The reason for this is that the scripts are running in different lua states and there is no easy way of passing more elaborate data (functions, rich Factorio objects - Lua Entity, etc.) around. Passing simple function callbacks is very powerful mechanism and might be implemented in some way in the future.

Re: [0.9] Require crash

Posted: Wed Mar 05, 2014 1:41 pm
by rk84
Ah I forgot that.