lua_result_t lua_bind_int(lua_t* env, const char* property, size_t length, int value) { #if BUILD_ENABLE_LUA_THREAD_SAFE if (!lua_acquire_execution_right(env, false)) { lua_op_t op; op.cmd = LUACMD_BIND_INT; op.data.name = property; op.size = length; op.arg.value[0].ival = value; lua_push_op(env, &op); return LUA_QUEUED; } lua_value_t val = { .ival = value }; lua_result_t res = lua_do_bind(env, property, length, LUACMD_BIND_INT, val); lua_execute_pending(env); lua_release_execution_right(env); return res; #else lua_value_t val = { .ival = value }; return lua_do_bind(env, property, length, LUACMD_BIND_INT, val); #endif }
lua_result_t lua_bind_function(lua_t* env, const char* method, size_t length, lua_fn fn) { #if BUILD_ENABLE_LUA_THREAD_SAFE if (!lua_acquire_execution_right(env, false)) { lua_op_t op; op.cmd = LUACMD_BIND; op.data.name = method; op.size = length; op.arg.value[0].fn = fn; lua_push_op(env, &op); return LUA_QUEUED; } lua_value_t val = { .fn = fn }; lua_result_t res = lua_do_bind(env, method, length, LUACMD_BIND, val); lua_execute_pending(env); lua_release_execution_right(env); return res; #else lua_value_t val = { .fn = fn }; return lua_do_bind(env, method, length, LUACMD_BIND, val); #endif }
void lua_execute_pending(lua_t* env) { profile_begin_block(STRING_CONST("lua exec")); unsigned int head = env->queue_head; while (env->queue[head].cmd != LUACMD_WAIT) { //Execute switch (env->queue[head].cmd) { case LUACMD_LOAD: lua_do_eval_stream(env, env->queue[head].data.ptr); break; case LUACMD_EVAL: lua_do_eval_string(env, env->queue[head].data.name, env->queue[head].size); break; case LUACMD_CALL: lua_do_call_custom(env, env->queue[head].data.name, env->queue[head].size, &env->queue[head].arg); break; case LUACMD_BIND: case LUACMD_BIND_INT: case LUACMD_BIND_VAL: lua_do_bind(env, env->queue[head].data.name, env->queue[head].size, env->queue[head].cmd, env->queue[head].arg.value[0]); break; default: break; } //Mark as executed env->queue[head].cmd = LUACMD_WAIT; if (++head == BUILD_LUA_CALL_QUEUE_SIZE) head = 0; } env->queue_head = head; profile_end_block(); }