size_t size mismatch in precompiled chunk. Unable to use loadfile to load precompiled lua bytecode.

I have a simple lua script here:

local string = "Hello World" print(string)

I have compiled this down to bytecode using luac53. However the problem arises when trying this:

local func = assert(loadfile("compiledlua.lua"))

This is where I get the:

“size_t size mismatch in precompiled chunk”.

I really have no idea why this is happening. Can anyone help me?

Hi varscott16, 

I tested your code on my computer (Win7 64bit with luarockwith built-in lua5.1.exe and luac5.1.exe). It works as expected. 

Which version of lua interpreter do you use? Do both interpreter and compiler are for 64bit or 32bit systems?

ldurniat

Corona uses Lua 5.1.5

A chunk compiled with 5.3 will be incompatible.

It was in fact a compatibility thing. The loadfile script works great when running from lua53.exe directly but my debugger in vscode was configured to use lua 5.1. Thank you guys for the help on this one!

Now that this has been answered I will ask why does the documentation say that loadfile()  is not available in Corona. 

From here at the end of the page.

The basic Lua library provides several core functions. For security reasons, the dofile(), load(), loadfile(), and loadstring() functions are not available in Corona.

I know we enabled loadstring(), but for a long time Apple would reject apps that tried to dynamically load executable code. They have eased that restriction somewhat, but any of those API’s we may have opened, but chose to not document them.

Rob

Hi varscott16, 

I tested your code on my computer (Win7 64bit with luarockwith built-in lua5.1.exe and luac5.1.exe). It works as expected. 

Which version of lua interpreter do you use? Do both interpreter and compiler are for 64bit or 32bit systems?

ldurniat

Corona uses Lua 5.1.5

A chunk compiled with 5.3 will be incompatible.

It was in fact a compatibility thing. The loadfile script works great when running from lua53.exe directly but my debugger in vscode was configured to use lua 5.1. Thank you guys for the help on this one!

Now that this has been answered I will ask why does the documentation say that loadfile()  is not available in Corona. 

From here at the end of the page.

The basic Lua library provides several core functions. For security reasons, the dofile(), load(), loadfile(), and loadstring() functions are not available in Corona.

I know we enabled loadstring(), but for a long time Apple would reject apps that tried to dynamically load executable code. They have eased that restriction somewhat, but any of those API’s we may have opened, but chose to not document them.

Rob