lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Greetings,

 

I have been working on a project integrating Lua onto a Freescale Kinetis microcontroller.  I have successfully created a simple shell that allows me to enter Lua statements (modeled after the shell shown in Programming in Lua).

 

I have written “C” functions to manage a Lua table that is to be used by a Lua script to pass parameters to a “C” function where the parameters are sent out a proprietary CAN stack.  The Lua table is created from a “C” function before the first lua_pcall is called.  Initially the table is as follows:

 

messagePayload =
{
  isRelativeLevel = 0,
  isFadeRate = 1,
  isWaitForGo = 0,
  isHighestTakePrecedence = 0,
  priority = 8,
  fade = 10,
  channelListCount = 0,
  Dimmers =
  {
    [0] = nil,
  }
}

 

One of the functions that can be called from “C” adds dimmer/level pairs to the Dimmers table.  For example, if the LuaScript called the “C” function with a dimmer number of 1 and a level of 128, the table would be modified as follows:

 

messagePayload =
{
  isRelativeLevel = 0,
  isFadeRate = 1,
  isWaitForGo = 0,
  isHighestTakePrecedence = 0,
  priority = 8,
  fade = 10,
  channelListCount = 0,
  Dimmers =
  {
    [0] = {dim = 1, lev = 128}
  }
}

 

Additional dimmer/level pairs can be added.

 

My question is this; I would like to be able to modify the values of members of the table from Lua, but I do not want Lua to be able to change the members or structure of the table, only the “C” functions are allowed to do this.  Is this possible?

 

Thanks,

 

Rick